【问题标题】:Shiny ggvis reactivity闪亮的 ggvis 反应性
【发布时间】:2015-06-23 14:41:04
【问题描述】:

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

我的代码如下:

用户界面:

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

                            # Layout
                            sidebarLayout(

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

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

服务器:

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")
  })

}

【问题讨论】:

  • 你能提供一些可重现的数据来重现错误吗?

标签: shiny interactive ggvis


【解决方案1】:

我想通了:

更新后的用户界面:

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")

})

【讨论】:

    猜你喜欢
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 2016-10-11
    • 2014-09-16
    相关资源
    最近更新 更多