[英]Show / Hide selectinput in R shiny based on tabpanel selection
I need to show different dropdown/selectinput for different tabs.我需要为不同的选项卡显示不同的下拉/选择输入。
Ex.前任。 If tab one is selected, then show selectinput with a list of values Tim, Bill, Jeff, ... If tab two is selected, then show selectinput with a list of values Cat, Dog, Squirrel, ...如果选择了选项卡一,则显示带有值列表的 selectinput Tim,Bill,Jeff,... 如果选择了选项卡二,则显示带有值列表的 selectinput Cat,Dog,Squirrel,...
I found the below script online but it does vice-versa ( shows/hides tabpanels based on selectinput selection - But I need show/hide selectinput based on tabpanel selection ).我在网上找到了下面的脚本,但反之亦然(根据 selectinput 选择显示/隐藏选项卡面板 - 但我需要根据选项卡面板选择显示/隐藏选项卡输入)。
runApp(list(
ui = shinyUI(
fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(
inputId = 'selected.indicator',
label = 'Select an option: ',
choices = c('mean', 'median', 'mode')
)
),
mainPanel(
tabsetPanel(
tabPanel("Prevalence / mean", value = 'meanTab', DT::dataTableOutput("prevtab")),
tabPanel("Subgroups comparison", value = 'medianTab', DT::dataTableOutput("comptab")),
id ="tabselected"
)
)
)
)
),
server = function(input, output, session) {
observe({
req(input$selected.indicator)
if (grepl("MEDIAN", toupper(input$selected.indicator), fixed = TRUE)) {
hideTab(inputId = "tabselected", target = 'medianTab')
}
else showTab(inputId = "tabselected", target = 'medianTab')
})
}
))
Here you go.这里是 go。
runApp(list(
ui = shinyUI(
fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(
inputId = 'selected.indicator',
label = 'Select an option: ',
choices = c('')
)
),
mainPanel(
tabsetPanel(
tabPanel("tab1", value = 'tab1', p("tab1")),
tabPanel("tab2", value = 'tab2', p("tab2")),
id ="tabselected"
)
)
)
)
),
server = function(input, output, session) {
choices <- reactiveValues(
tab1 = c('Tim', 'Bill', 'Jeff'),
tab2 = c('Cat', 'Dog', 'Squirrel')
)
observeEvent(input$tabselected, {
updateSelectInput(session, 'selected.indicator', choices = choices[[input$tabselected]])
})
}
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.