conditionalPanel works fairly reliably in the shinydashboard sidebar as excellently documented
here. However, to my chagrin, it fails me or more likely nowadays I fail it. Here is the code to illustrate my point.
The sidebarMenu is given an id="sbm", I wish to display a hr() if the "Tab 2" is clicked. The conditionalPanel can be put in either ui or server function, the hr won't display. In my browser inspect id="sbm" is nowhere to be found. Instead, the "menu" appears to be the id (see the attachment). The hr() still refuses to appear even I use the menu as id.
I tried to do the same thing not using dynamically generated sidebar menu, I can see id="sbm" exactly where I expected to see.
So my questions are
- why the sidebarMenu id couldn't be assigned, instead the name of ouput$xxx object is used as id
- how to create conditionalPanel in sidebar menu when sidebar menu is dynamically generated
Any insight and advice is greatly appreciated.
==================================
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Dynamic sidebar"),
dashboardSidebar(
sidebarMenuOutput("menu")
,conditionalPanel(condition = "input.sbm == 'tab2'", hr())
),
dashboardBody()
)
server <- function(input, output) {
output$menu <- renderMenu({
sidebarMenu(id = "sbm",
menuItem("Home", tabName="tabHome", icon = icon("home")),
menuItem("Tab 2", tabName="tab2", icon = icon("calendar"))
# ,conditionalPanel(condition = "input.sbm == 'tab2'", hr())
# ,conditionalPanel(condition = "input$sbm == 'tab2'", hr())
)
})
}