无法 select 返回已在 Shiny R 中 select 的菜单项

Unable to select back a menu Item already selected in Shiny R

我在使用 shiny dashborad 时遇到了一个奇怪的问题,我无法 select 返回我已经 select 编辑过一次的菜单项。

请在下面找到我的代码,它非常基础,如果您发现任何问题,我将不胜感激:


ui <-dashboardPage( dashboardHeader(title = "Dashborad"  ),

dashboardSidebar(
  menuItem("A", tabName = "A", icon = icon("users")),
  menuItem("B",  tabName = "B",icon = icon("hand-holding-usd"),
           
           menuItem("B1",  tabName = "b1", icon = icon('line-chart')),
           menuItem('B2',  tabName = "b2", icon = icon('line-chart')),
           menuItem('B3',  tabName = "b3", icon = icon('line-chart'))
  ),
  
  menuItem("C", tabName = "c", icon = icon("shopping-cart")),
  menuItem("D", tabName = "d", icon = icon("ellipsis-h"))
),

dashboardBody(
  tabItems( tabItem(tabName = "A",h2("AAAAAAAAAAAa")),
            tabItem(tabName = "b1",h2("BBBBBBBBBBBb1111")),
            tabItem(tabName = "b2",h2("BBBBBBBBBBBBBb222")),
            tabItem(tabName = "b3",h2("BBBBBBBBBBBB3333")),
            tabItem(tabName = "c",h2("CCCCCCCCCCCCccc")),
            tabItem(tabName = "d",h2("DDDDDDDDDDDDDdd"))
  )))

server <- function(input, output,server) {}
shinyApp(ui, server)

您错过了将 menuItem() 包裹在 sidebarMenu() 中。见dashboardSidebar()的描述:

A dashboardSidebar can contain a sidebarMenu. A sidebarMenu contains menuItems, and they can in turn contain menuSubItems.

library(shinydashboard)
ui <-dashboardPage( dashboardHeader(title = "Dashborad"  ),
                    
                    dashboardSidebar(
                      sidebarMenu(
                      menuItem("A", tabName = "A", icon = icon("users")),
                      menuItem("B",  tabName = "B",icon = icon("hand-holding-usd"),
                               
                               menuSubItem("B1",  tabName = "b1", icon = icon('line-chart')),
                               menuSubItem('B2',  tabName = "b2", icon = icon('line-chart')),
                               menuSubItem('B3',  tabName = "b3", icon = icon('line-chart'))
                      ),
                      
                      menuItem("C", tabName = "C", icon = icon("shopping-cart")),
                      menuItem("D", tabName = "D", icon = icon("ellipsis-h"))
                    )),
                    
                    dashboardBody(
                      tabItems( tabItem(tabName = "A",h2("AAAAAAAAAAAa")),
                                tabItem(tabName = "b1",h2("BBBBBBBBBBBb1111")),
                                tabItem(tabName = "b2",h2("BBBBBBBBBBBBBb222")),
                                tabItem(tabName = "b3",h2("BBBBBBBBBBBB3333")),
                                tabItem(tabName = "C",h2("CCCCCCCCCCCCccc")),
                                tabItem(tabName = "D",h2("DDDDDDDDDDDDDdd"))
                      )))

server <- function(input, output,server) {}
shinyApp(ui, server)