Hide sidebar in default in shinydashboard

后端 未结 2 395
太阳男子
太阳男子 2021-01-02 01:28

I used shinydashboard to create my app. I would like to hide the sidedar in default on desktop environment (e.g. windows), but not to disable it. On the mobile

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 02:06

    This is very similar to my answer from another SO thread: "disabling/enabling sidebar from server side"

    Here's code that can do what you want by hiding the sidebar when the app starts (using the package shinyjs)

    library(shiny)
    library(shinydashboard)
    library(shinyjs)
    
    ui <- shinyUI(dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      dashboardBody(
        useShinyjs()
      )
    ))
    
    server <- shinyServer(function(input, output, session) {
      addClass(selector = "body", class = "sidebar-collapse")
    })
    
    shinyApp(ui = ui, server = server)
    

提交回复
热议问题