I have a Shiny app where I would like to set a conditionalPanel()
depending on whether the user selects a tabPanel
from a tabBox
. My question is how can I reference the panel the user selected. In my example the idea is that if the user selects "Panel1" there appears a conditional panel. As you will see I tried to set the condition in the conditionalPanel()
call as condition = "input.tabs.tab1.box == 'p1'"
.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
skin = "green",
dashboardHeader(title = "Referencing Box"),
dashboardSidebar(
width = 250,
sidebarMenu(
id = "tabs",
menuItem("First Tab", tabName = "tab1",
menuSubItem("Box", tabName = "box"))
)
),
dashboardBody(
tabItem(
tabName = "box",
tabBox(
id = "tb",
title = "Two Panels",
tabPanel(
id = "p1",
title = "Panel1"
),
tabPanel(
id = "p2",
title = "Panel2"
)
),
conditionalPanel(
condition = "input.tabs.tab1.box == 'p1'",
box(
id = "p3",
title = "Conditional Panel"
)
)
)
)
)
server <- function(input, output) { }
shinyApp(ui, server)
I've seen some examples around where people referenced the upmost layer, so a menuItem
with conditions like condition = "input.tabs == 'anova'"
, but in this case the referenced item is within a tabItem
and further within a tabBox
call.