Conditional panel in Shiny dashboard

南楼画角 提交于 2019-12-10 12:31:10

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/29925585/conditional-panel-in-shiny-dashboard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!