2

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 なので、~mpgand~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")
4

1 に答える 1

4

これは機能します:

  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")
    }
  })
于 2014-12-12T15:03:11.107 に答える