Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional panel in Shiny dashboard

Tags:

r

dashboard

shiny

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 :)

like image 463
Damian Avatar asked Apr 28 '15 17:04

Damian


1 Answers

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())
like image 135
Damian Avatar answered Nov 06 '22 11:11

Damian