Search code examples
rshinyshinydashboard

Move sidebarMenu to top when header is disabled in shinydashboard


I want to have the header disabled in my shinydashboard, and I want the first item in the menu on the sidebar to be placed at the absolute top of the sidebar, where it by default is placed a little lower. Is there a way to move it up there?

ui <- shinydashboard::dashboardPage(
  shinydashboard::dashboardHeader(disable = TRUE),
  shinydashboard::dashboardSidebar(
    sidebarMenu(
      menuItem("Home", tabName = "home", icon = icon("house"))
  )),
  shinydashboard::dashboardBody(
    shinydashboard::tabBox(
      title = "title",
      shiny::tabPanel(
        "test panel"
        )
      )
    )
)

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

shiny::shinyApp(ui, server)

enter image description here


Solution

  • I have modified the code:

    library(shiny)
    library(shinydashboard)
    library(shinyjs)
    
    ui <- shinydashboard::dashboardPage(
        shinydashboard::dashboardHeader(disable = TRUE),
        shinydashboard::dashboardSidebar(
            tags$style(HTML(".main-sidebar {padding-top: 0px !important;}")),
            sidebarMenu(
                menuItem("Home", tabName = "home", icon = icon("house"))
            )
        ),
        shinydashboard::dashboardBody(
            shinydashboard::tabBox(
                title = "title",
                shiny::tabPanel(
                    "test panel"
                )
            )
        )
    )
    
    server <- function(input, output, session) {
    }
    
    shiny::shinyApp(ui, server)
    

    Running this app, produces:

    enter image description here

    Check if this is what you wanted?