【问题标题】:Dynamic UI Shiny Implementation动态 UI 闪亮实现
【发布时间】:2014-04-21 01:33:35
【问题描述】:

我有以下数据框:

a<-rep(c("cat","dog","bird"),each=5)
b<-letters[1:length(a)]
c<-data.frame("pet"=a,"level"=b)

我想制作一个闪亮的应用程序,它有一个用于选择pet 的下拉菜单,然后在下方显示一组动态复选框,复选框选项对应的值为level

因此,选择cat 会弹出a,b,c,d,e 的复选框组,然后选择dog 会将这些复选框更改为仅显示f,g,h,i,j 等。

感谢您的帮助

【问题讨论】:

    标签: r user-interface dynamic shiny


    【解决方案1】:

    您可以在观察者内部使用updateCheckboxGroupInput 函数(?observe observe 函数“观察”input$petand 并会在input$pet 更改时自动重新执行,然后更新复选框组)。

    例如:

    a<-rep(c("cat","dog","bird"),each=5)
    b<-letters[1:length(a)]
    c<-data.frame("pet"=a,"level"=b)
    
    runApp(list(
      ui = pageWithSidebar(
        headerPanel("Example"),
    
        sidebarPanel(
          selectInput("pet", "Select a pet", choices = levels(c$pet), selected = levels(c$pet)[1]),
          tags$hr(),
          checkboxGroupInput('levels', 'Levels', choices = c$level[c$pet == levels(c$pet)[1]])
        ),
    
        mainPanel()
      ),
      server = function(input, output, session) {
    
        observe({
          pet <- input$pet
    
          updateCheckboxGroupInput(session, "levels", choices = c$level[c$pet == pet])
        })
      }
    ))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 2020-06-14
      • 2020-10-29
      • 2021-05-06
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多