R Shiny - 条件面板

时间:2016-04-21 13:48:53

标签: r shiny shiny-server

我想知道是否可以在另一个条件面板中设置一个条件面板。

例如,如果我有一个包含两个选项的下拉列表:1和2

选择1将显示一组选项,选择2将显示一组不同的选项。

但是可以将条件面板嵌套在这些条件面板中,这样我就可以在选项1的输入中有另一个下拉列表。

以下是我尝试做的一些示例的代码,但这不起作用

 selectInput("n", label = h3("Select Option"), 
                choices = list("1" = 1, "2" = 2),
                selected = 1),
  #1
  conditionalPanel(
    condition = "input.n == '1'",
    titlePanel("1 Options"),
    selectInput("b", label = h4("Select Option"), 
                choices = list("A" = 1, "B" = 2),
conditionalPanel(
condition = "input.b == '1'",
    titlePanel("1 Options")
),

conditionalPanel(
condition = "input.b == '2'",
    titlePanel("2 Options")
),

    )),

1 个答案:

答案 0 :(得分:0)

是的,您可以轻松地嵌套条件面板,或多或少地尝试。在你的代码中,你只是有一些错位的括号和额外的逗号。这是一个有用的应用程序,可以满足您的需求,我认为:

ui <- fluidPage(
  selectInput("n", label = h3("Select Option"), 
        choices = list("1" = 1, "2" = 2),
        selected = 1),
  conditionalPanel(
    condition = "input.n == '1'",
    titlePanel("1 Options"),
    selectInput("b", label = h4("Select Option"), 
          choices = list("A" = 1, "B" = 2)),
    conditionalPanel(
          condition = "input.b == '1'",
          titlePanel("1 Options")
      ),
      conditionalPanel(
          condition = "input.b == '2'",
          titlePanel("2 Options")
      )      
  )
)

server <- function(input, output){}

shinyApp(ui, server)
相关问题