如何在闪亮的情况下创建层次结构反应表和菜单

时间:2015-07-19 13:43:51

标签: r shiny hierarchy

我想用反应表输出做一个层次结构菜单。我希望我的应用程序执行以下操作:

  1. 当我选择brand = w时,我可以选择的模型输入应该只是w的较低层次结构(在这种情况下:model应该是w123和{{1表格输出应该是w456

  2. 的子集
  3. 当我选择brand = w和model = w123时,表格输出应列出brand w

  4. 的子集

    这是我的代码,任何人都可以帮助我吗?感谢

    UI:

    brand = w & model = w123

    服务器

    library(shiny)
    
    shinyUI((fluidPage(
       titlePanel("hirearchy data group"),
       sidebarLayout
       (
       sidebarPanel
       (
       selectInput("brand",label="choice the brand",choices=c("all","w","s")),
       selectInput("model",label="choice the model",choices=c("all","w123","w456","s99","s88"))
    
       ),
    
       mainPanel
       (
       dataTableOutput("table")
       )
    
       ))))
    

1 个答案:

答案 0 :(得分:1)

将此代码添加到您的服务器:

  # This gets re-evaluated when input$brand changes
  observeEvent(input$brand, {
    brand <- input$brand

    # Available model options based on brand
    choices <- switch(brand, "w" = c("all","w123","w456"),
                             "s" = c("all","s99","s88"),
                           "all" = c("all","w123","w456","s99","s88"))

    # Update the model input object to only display wanted choices                  
    updateSelectInput(session, "model", choices = choices)
  })

为了使updateSelectInput起作用,您还需要修改服务器功能定义以包含session对象:您的服务器定义应显示为shinyServer(function(input, output, session) {