Hide sidebar in default in shinydashboard

て烟熏妆下的殇ゞ 提交于 2019-12-30 04:36:24

问题


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 device, the sidebar is hide in default. I think I need to change the css class, but don't know how to do it.

Thanks for any suggestions.

This is my playing codes:

library(shiny)

library(shinydashboard)
ui <- shinyUI(dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody()
))

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

shinyApp(ui = ui, server = server)

回答1:


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)



回答2:


if you do a ?dashboardSidebar you probably see the usage, like this

dashboardSidebar(..., disable = FALSE, width = NULL, collapsed = FALSE)

So this should work

sidebar <- dashboardSidebar(
  collapsed = TRUE,
  sidebarMenu()
)

i'm not sure if this depends on your shinydashboard version but you could check/change that as well.



来源:https://stackoverflow.com/questions/35170065/hide-sidebar-in-default-in-shinydashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!