闪亮的ggvis反应性

时间:2015-04-16 23:07:18

标签: shiny interactive ggvis

我试图创建一个响应按钮选择的ggvis图。当我运行它时,选中的第一个按钮将显示一个很好的ggvis图,但是一旦我改变了选择,我可以看到一个非常简短的新情节一瞥,然后它消失了。之后,我看不到任何情节。

我的代码如下:

UI:

shinyUI(navbarPage("Perspective:",
                   tabPanel("Overview",

                            # Layout
                            sidebarLayout(

                              sidebarPanel(
                                radioButtons("marker", "Phenotypic Marker:", phenotypic_marker_names)),

                              mainPanel(htmlOutput("myplot"))
                            )
                   )
))

SERVER:

shinyServer(function(input, output) {  

  dataInput <- reactive({
    data[[input$marker]]
  })

  observe({
    if (!is.null(input$marker)) {
      dl <- dataInput()
      dl %>%
        ggvis(x = ~as.numeric(time_elapsed), y = ~as.numeric(phenotype_value)) %>%
        bind_shiny("allsparklines")
    }
  })

  output$myplot <- renderUI({
    if(is.null(input$marker)) {
      return(NULL)
    }
    ggvisOutput("allsparklines")
  })

}

1 个答案:

答案 0 :(得分:0)

我明白了:

更新的用户界面:

shinyUI(navbarPage("Perspective:",
                   tabPanel("Overview",

                            # Layout
                            sidebarLayout(

                              sidebarPanel(radioButtons("marker", "Phenotypic Marker:", phenotypic_marker_names)),

                              mainPanel(ggvisOutput("allsparklines"))
                            )
                   )
))

更新的服务器:

shinyServer(function(input, output, session) {

  selected <- reactive({
    if (!is.null(input$marker)) {
      data_temp[[input$marker]]
    }
  })


  selected %>% 
    ggvis(x = ~as.numeric(time_elapsed), y = ~as.numeric(phenotype_value)) %>%
    layer_points() %>%
    bind_shiny("allsparklines")

})