Shinydashboard: Is it not possible to have nested menu sub items? Can't make it work

只谈情不闲聊 提交于 2020-01-01 02:29:10

问题


I am using a shinydashboard, and have a need to build two-level nested sub menus. I am trying this and won't work:

library(shinydashboard)
sidebar <- dashboardSidebar(
  sidebarMenu(id = 'sidebarmenu',
              menuItem('x', tabName = 'x', icon = icon('line-chart')),
              menuItem('y', tabName = 'y',
                       icon = icon('line-chart'),
                       menuSubItem('a',
                                   tabName = 'a',
                                   icon = icon('line-chart')),
                       menuSubItem('b',
                                   tabName = 'b',
                                   icon = icon('line-chart'),
                                   menuSubItem('l',
                                               tabName = 'l',
                                               icon = icon('line-chart')),
                                   menuSubItem('m',
                                               tabName = 'm',
                                               icon = icon('line-chart'))),
                       menuSubItem('c',
                                   tabName = 'c',
                                   icon = icon('line-chart'))
              )))

Gives me error:

Error in menuSubItem("b", tabName = "b", icon = icon("line-chart"), menuSubItem("l",  : 
  Can't specify both href and tabName

Is it possible to build two-level nesting? Of course, removing l and m sub menus above works just fine (with one level sub menus).


回答1:


It works if you only use menuSubItem as the lowest level, and call the others menuItem. Will that work for your purposes?

sidebar <- dashboardSidebar(
sidebarMenu(id = 'sidebarmenu',
            menuItem('x', tabName = 'x', icon = icon('line-chart')),
            menuItem('y', tabName = 'y',
                     icon = icon('line-chart'),
                     menuItem('a',
                                 tabName = 'a',
                                 icon = icon('line-chart')),
                     menuItem('b',
                                 tabName = 'b',
                                 icon = icon('line-chart'),
                                 menuSubItem('l',
                                             tabName = 'l',
                                             icon = icon('line-chart')),
                                 menuSubItem('m',
                                             tabName = 'm',
                                             icon = icon('line-chart'))),
                     menuItem('c',
                                 tabName = 'c',
                                 icon = icon('line-chart'))
            )))


来源:https://stackoverflow.com/questions/37597136/shinydashboard-is-it-not-possible-to-have-nested-menu-sub-items-cant-make-it

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