Shinydashboard vs shinydashboardPlus - Dashboardsidebar Title Differences

I have a Shiny app built with shinydashboard and I've just discovered shinydashboardPlus. One nice option is to have the sidebarMenu "minified", or when minimized it doesn't go away completely, but just displays the icons for each menuItem. However, with shinydashboardPlus, when minified, the title gets chopped off. With shinydashboard, the title stays intact, but the sidebar goes away completely.

Example code:

library(shiny)
library(shinydashboard)
#library(shinydashboardPlus)

# Basic dashboard page template
shinyApp(
  ui = dashboardPage(
    dashboardHeader(title = "Example"),
    dashboardSidebar(#minified = TRUE,
      sidebarMenu(
        menuItem('Menu1', tabName = 'Menu1', 
                 icon = icon('folder-open')),
        menuItem('Menu2', tabName = 'Menu2',
                 icon = icon('code-branch'))
      )
    ),
    dashboardBody()
  ),
  server = function(input, output) { }
)

Leaving the comment marks in place and running it uses shinydashboard, and gives this initially:

And when the hamburger is clicked to minimize the sidebar, the whole sidebar disappears:

If the comment marks are removed so that it runs using shinydashboardPlus, minimizing it gives this, where I have the icons in the sidebar, but the title is chopped:

Is there a way to get the shinydashboardPlus minification that shows just the icons, but doesn't chop off the title?

2

1 Answer

Here you go

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

# Basic dashboard page template
shinyApp(
  ui = dashboardPage(
    dashboardHeader(title = "Example"),
    dashboardSidebar(#minified = TRUE,
      sidebarMenu(
        menuItem('Menu1', tabName = 'Menu1', 
                 icon = icon('folder-open')),
        menuItem('Menu2', tabName = 'Menu2',
                 icon = icon('code-branch'))
      )
    ),
    dashboardBody(
      tags$style(
        '
        @media (min-width: 768px){
          .sidebar-mini.sidebar-collapse .main-header .logo {
              width: 230px; 
          }
          .sidebar-mini.sidebar-collapse .main-header .navbar {
              margin-left: 230px;
          }
        }
        '
      )
    )
  ),
  server = function(input, output) { }
)

change the width and margin-left numbers if you have extreme long titles.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest