I am not very familiar with dashboards, since I never built them, but looking at a quick view, it seems that when I click on the open / hide sidebar button, all that happens is the sidebar-collapse class, which is added / removed in the <body> . Perhaps more things happen that I donโt suspect, but that seemed to be the most noticeable.
So you can easily use shinyjs package (disclaimer: I am the author) to add / remove this class
library(shiny) library(shinydashboard) library(shinyjs) shinyApp( ui = dashboardPage( dashboardHeader(), dashboardSidebar(), dashboardBody( shinyjs::useShinyjs(), actionButton("showSidebar", "Show sidebar"), actionButton("hideSidebar", "Hide sidebar") ) ), server = function(input, output, session) { observeEvent(input$showSidebar, { shinyjs::removeClass(selector = "body", class = "sidebar-collapse") }) observeEvent(input$hideSidebar, { shinyjs::addClass(selector = "body", class = "sidebar-collapse") }) } )
source share