我正在尝试使用Shiny和ggvis来:
1)上传数据集
2)让用户选择两列(x,y)
3)返回一个显示从上传的数据集中提取的(x,y)的ggvis图表
我已经尝试编辑Shiny Interactivity页面的示例以及电影浏览器示例。但是,没有显示任何图表。
我认为我的问题在于上传数据集,但我不知道从哪里开始...有什么建议吗?
注意-我也尝试过使用rCharts,但我遇到了类似的问题,即没有显示任何图表。
1)上传数据集
2)让用户选择两列(x,y)
3)返回一个显示从上传的数据集中提取的(x,y)的ggvis图表
我已经尝试编辑Shiny Interactivity页面的示例以及电影浏览器示例。但是,没有显示任何图表。
我认为我的问题在于上传数据集,但我不知道从哪里开始...有什么建议吗?
注意-我也尝试过使用rCharts,但我遇到了类似的问题,即没有显示任何图表。
server.R
library(shiny)
library(dplyr)
library(ggvis)
shinyServer(function(input, output, session) {
fileHeaderNames <- reactive({
infile <- input$datfile
if(is.null(infile))
return(NULL)
d <- read.csv(infile$datapath, header = T)
return(names(d))
})
# dynamic variable names
observe({
updateSelectInput(session, 'x', choices = fileHeaderNames())
updateSelectInput(session, 'y', choices = fileHeaderNames())
}) # end observe
# uploading data set
theData <- reactive({
validate(
need(input$datfile != "", "Please upload a file")
)
infile <- input$datfile
dat <- read.csv(infile$datapath,
header = T,
stringsAsFactors = F)
if(is.null(infile)) return(NULL)
data.frame(x = dat[, input$x],
y = dat[, input$y])
})
# A simple visualisation. In shiny apps, need to register observers
# and tell shiny where to put the controls
theData %>%
ggvis(~x, ~y) %>%
layer_points() %>%
bind_shiny("plot", "plot_ui")
})
ui.R
library(ggvis)
library(shiny)
shinyUI(pageWithSidebar(
div(),
sidebarPanel(
fileInput('datfile', ''),
selectInput('x', 'x:' ,'x'),
selectInput('y', 'y:', 'y'),
uiOutput("plot_ui")
),
mainPanel(
ggvisOutput("plot")
)
))