CSV を入力として使用し、ボタンが押されたときにロードする Shiny アプリがあります。
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)
}
})
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")
})
ここで私の CSV 入力は mtcars.csv なので、~mpg
and~wt
を列として使用します。パーツを取り出して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")