【发布时间】:2015-03-26 10:47:02
【问题描述】:
我正在尝试使用 Shiny 和 ggvis 来:
1) 上传数据集
2) 让用户选择 2 列 (x, y)
3) 从上传的数据集中返回一个显示 (x, y) 的 ggvis 图
我尝试编辑 Shiny Interactivity 页面和 movie explorer 示例中的示例。但是,没有显示图表。
我认为我的问题是关于上传数据集,但我不知道从哪里开始...有什么建议吗?
注意 - 我也尝试过使用 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")
)
))
【问题讨论】:
-
我可以让它与 googleVis 一起使用,但我想使用该软件包中没有的一些功能。