Search code examples
rshinyshinydashboard

Totally hide left sidebar of shiny dashboard by clicking on existing toggle button without affecting the title section


How is it possible to hide the left sidebar of a shinydashboard() totally without also affecting the header section that almost hides the title by using the toggle button that is already there?

## app.R ##
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)

ui <- dashboardPage(
  dashboardHeader(title = "dashboard"
    
  ),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs(),
    tags$hr(),
    tabsetPanel(
      id ="tabA",
      type = "tabs",
      tabPanel("Front",icon = icon("accusoft")),
      tabPanel("Data", icon = icon("table")
      )
    )
  ),
  controlbar = dashboardControlbar()
  
)

server <- function(input, output) {
  
}

shinyApp(ui = ui, server = server)

Solution

  • Just use shinydashboardPlus::dashboardSidebar()'s minified parameter:

    library(shiny)
    library(shinydashboard)
    library(shinydashboardPlus)
    library(shinyjs)
    
    ui <- dashboardPage(
      dashboardHeader(title = "dashboard"),
      dashboardSidebar(minified = FALSE),
      dashboardBody(
        useShinyjs(),
        tags$hr(),
        tabsetPanel(
          id ="tabA",
          type = "tabs",
          tabPanel("Front",icon = icon("accusoft")),
          tabPanel("Data", icon = icon("table")
          )
        )
      ),
      controlbar = dashboardControlbar()
    )
    
    server <- function(input, output, session) {}
    
    shinyApp(ui = ui, server = server)