【问题标题】:How to enable a particular sub-menu in Rshiny?如何在 R Shiny 中启用特定的子菜单?
【发布时间】:2018-09-22 18:18:22
【问题描述】:

我正在使用仪表板包开发一个 shinyApp。因为一个菜单项有 2 个子菜单,应用程序必须根据子菜单的选择做出反应。但是如果不选择子菜单,我就会显示我的数据。谁能帮我解决这个问题? 这是使用的代码 sn-p。提前致谢。

dashboardSidebar(
    sidebarMenu(
       menuItem('Modify',
                menuSubItem('Edit details', tabName = 'edit'),
                    )
      )),

    dashboardBody(
      tabItems(
        tabItem(tabName = 'edit', 
                hotable('hotable1'),
                downloadButton('downloadData', 'Download')
        )
      )

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    我认为我没有完全理解您的问题,但据我收集的信息,您质疑为什么该表出现在应用程序初始化时,而用户没有单击 menuSubItem。这是 Shiny Dashboard 中的默认行为,应用程序将从第一个 menuSubItem 作为默认值开始,如果您希望将特定的 menuSubItem 作为启动子选项卡,可以使用 @ 下的 selected 选项来实现987654326@

    这是一个展示相同行为的可重现示例,为了明确突出此行为,我使用了startExpanded = TRUE。在这里你可以观察到第一个 subMenuItem 默认被选中。更多关于childfull menuItem()的内容可以参考here

    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(), 
      dashboardSidebar(
        sidebarMenu(
          menuItem("Modify",startExpanded = TRUE,
                   menuSubItem("Sub-item 1", tabName = "subitem1"),
                   menuSubItem("Sub-item 2", tabName = "subitem2")
          )
        )
      ),
      dashboardBody(
        tabItems(
          tabItem("subitem1", "Sub-item 1 tab content"),
          tabItem("subitem2", "Sub-item 2 tab content") 
        )
      )
    )
    
    server <- function(input, output, session) {
    
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2017-10-24
      • 2021-10-13
      • 1970-01-01
      • 2020-01-04
      • 2019-09-18
      • 2017-10-04
      • 2017-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多