Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy R shinydashboard with menuSubItem not collapsed by default

Below is some simple sample code for shinydashboard with various subMenuItem objects under a menuItem. By default, when the app is deployed the subMenuItems are collapsed. Is there a way to set it so that they are not collapsed?

ui <- dashboardPage(
  dashboardHeader(title='Head'),
  dashboardSidebar(
    sidebarMenu(
      menuItem('Tabs', tabName='tabs',
        menuSubItem('Tab 1', tabName='tab1'),
        menuSubItem('Tab 2', tabName='tab2'),
        menuSubItem('Tab 3', tabName='tab3')
      )
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName='tab1',
        h1("Tab 1")
      ),
      tabItem(tabName='tab2',
        h1("Tab 2")
      ),
      tabItem(tabName='tab3',
        h1("Tab 3")      
      )
    )
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)
like image 804
Gaurav Bansal Avatar asked Jan 06 '23 17:01

Gaurav Bansal


1 Answers

You can use Javascript to change the default display style of the menu elements (by default they are display:none which needs to be changed to display:block). Add the following line after menuItem() (remember to add a comma also)

  tags$head(tags$script(HTML('$(document).ready(function() {$(".treeview-menu").css("display", "block");})')))
like image 53
Xiongbing Jin Avatar answered Jan 08 '23 06:01

Xiongbing Jin