[英]Use reactive function as ggvis input
I have a Shiny app that uses a CSV as input and load when a button is pressed. 我有一个Shiny应用程序,使用CSV作为输入并在按下按钮时加载。
shinyServer(function(input, output) {
dataInput <- reactive({
if(is.null(input$file)) {
return(NULL)
}
butt$a
})
butt <- reactiveValues()
observe({
if (input$goButton == 0) {
butt$a <- return(NULL)
}
if (input$goButton > 0) {
butt$a <- read.csv(input$file$datapath,
header = input$header,
sep = input$sep, quote = input$quote)
}
})
And I would like to use dataInput()
as an input for a ggvis plot: 我想使用dataInput()
作为ggvis图的输入:
output$ggvisplot_ui <- renderUI({
if(is.null(butt$a)) {
return(NULL)
}
ggvisOutput("ggvisplot")
})
reactive({
dl <- dataInput()
dl %>%
ggvis(~mpg, ~wt) %>%
layer_points() %>%
bind_shiny("ggvisplot")
})
Here my CSV input is mtcars.csv so I use ~mpg
and ~wt
as columns. 在这里我的CSV输入mtcars.csv所以我用~mpg
和~wt
为列。 If I take out the reactive({ })
part replace dl <- dataInput()
with dl <- mtcars
it works just fine: 如果我拿出dl <- dataInput()
reactive({ })
部分,将dl <- dataInput()
替换为dl <- mtcars
它就可以正常工作:
output$ggvisplot_ui <- renderUI({
if(is.null(butt$a)) {
return(NULL)
}
ggvisOutput("ggvisplot")
})
dl <- mtcars
dl %>%
ggvis(~mpg, ~wt) %>%
layer_points() %>%
bind_shiny("ggvisplot")
This works: 这有效:
output$ggvisplot_ui <- renderUI({
if(is.null(butt$a)) {
return(NULL)
}
ggvisOutput("ggvisplot")
})
observe({
if (!is.null(butt$a)) {
dl <- dataInput()
dl %>%
ggvis(~mpg, ~wt) %>%
layer_points() %>%
bind_shiny("ggvisplot")
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.