Damian
Damian

Reputation: 439

Conditional panel in Shiny dashboard

I have a question about conditional panel in shiny dashboard. Is there a possibility to make conditional panel with condition on menuItem in sidebarMenu? My goal is to obtain an additional selectInput after click on menu tab title2 (but it should stay invisible for title1 tab).

I am doing something like follows

ui <- dashboardPage(
    dashboardHeader(title = "Basic Dashboard"),
    dashboardSidebar(
        sidebarMenu(
            menuItem("tab title1", tabName = "name1", icon = icon("th")),
            menuItem("tab title2", tabName =  "name2", icon = icon("th"))
         ),
        conditionalPanel(
            condition = "input.tabName == 'name2'",
            selectInput("period", "Period:", 
                        choices = list("Years" = 1, "Months" = 2))
        )
        ),
    dashboardBody())

In standard shiny it could be done by add , value=1 to tab but here it doesn't work. Does anyone know any solution? Thanks in advance :)

Upvotes: 20

Views: 9218

Answers (1)

Damian
Damian

Reputation: 439

Adding an extra argument id to sidebarMenu solves the problem.

ui <- dashboardPage(
dashboardHeader(title = "Basic Dashboard"),
dashboardSidebar(
    sidebarMenu(id="menu1",
        menuItem("tab title1", tabName = "name1", icon = icon("th")),
        menuItem("tab title2", tabName =  "name2", icon = icon("th"))
     ),
    conditionalPanel(
        condition = "input.menu1 == 'name2'",
        selectInput("period", "Period:", 
                    choices = list("Years" = 1, "Months" = 2))
    )
    ),
dashboardBody())

Upvotes: 23

Related Questions