如果在sidebarPanel()
的{{1}}中选择了过滤器,我试图有条件地在inputSelect()
中显示过滤器。
使用下面的示例,Shiny应用程序不应以在sidebarPanel中显示“ lob_choice”或“ segment_choice”过滤器开始,并且我有以下要求:
如果在“ filter_choice”过滤器中选择了下面的代码,则下面的代码将显示其中一个条件面板,但是如果同时选择了两个代码,则不会显示任何一个条件面板。
multiple = TRUE
ui <- fluidPage(
titlePanel("Test App"),
sidebarLayout(
sidebarPanel(
h3("Parameters"),
selectInput("filter_choice",
"In which ways would you like to filter the data?",
c("LOB",
"Segment"),
selected = NULL,
multiple = TRUE),
conditionalPanel(condition = "input.filter_choice == 'LOB'",
selectInput("lob_choice",
"Choose Line(s) of Business:",
c("Brandon", "Kyler", "Trent"),
selected = NULL,
multiple = TRUE)),
conditionalPanel(condition = "input.filter_choice == 'Segment'",
selectInput("segment_choice",
"Choose Segment(s):",
c("LA", "Inverness", "Orlando"),
selected = NULL,
multiple = TRUE))),
mainPanel(tableOutput("table"))
)
)
答案 0 :(得分:1)
来自?Conditional Panel
condition一个JavaScript表达式,将对其进行重复评估,以确定是否应显示面板
所以在这里我们可以使用JS indexOf检查 filter_choice
condition = "input.filter_choice !== null && input.filter_choice.indexOf('LOB') >= 0"
#and
condition = "input.filter_choice !== null && input.filter_choice.indexOf('Segment') >= 0"