RinteRface / shinydashboardPlus

extensions for shinydashboard
https://shinydashboardplus.rinterface.com
Other
454 stars 77 forks source link

input$sidebarCollapsed does not work #57

Closed ivokwee closed 3 years ago

ivokwee commented 4 years ago

Hi,

I think the input$sidebarCollapsed does not work for shinydashboardPlus. It works for dashboardPage but as soon as I use dashboardPagePlus it does not work.

The code below does not work properly.

Ivo

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

ui <- dashboardPagePlus(
    dashboardHeader(), 
    dashboardSidebar(),
    dashboardBody(
        textOutput("res")
    )
)

server <- function(input, output, session) {
    output$res <- renderText({
        if (input$sidebarCollapsed) {
            "Sidebar is collapsed"
        } else {
            "Sidebar is expanded"
        }
    })
}

shinyApp(ui, server)
ivokwee commented 4 years ago

I also tried using dashboardHeaderPlus() but also doesn't work.

DivadNojnarg commented 4 years ago

Thanks for the report

micahwilhelm commented 4 years ago

any movement on this?

Cattiva commented 4 years ago

I ran in the same problem today and found this solution:

https://www.r-bloggers.com/three-r-shiny-tricks-to-make-your-shiny-app-shines-23-semi-collapsible-sidebar/

As mentioned in the blog post, it works by creating a new input value for clicking the sidebar-toggle button with

tags$script("$(document).on('click', '.sidebar-toggle', function () {
      Shiny.onInputChange('SideBar_col_react', Math.random())});"),

then create TRUE and FALSE values with

vals<-reactiveValues()
  vals$collapsed=FALSE
  observeEvent(input$SideBar_col_react,{
                 vals$collapsed=!vals$collapsed
  })

and finally creating a new reactive expression with the new vals$collapsed parameter that reacts on clicking the toggle button.

 size <- reactive({
    if(vals$collapsed){
      return("50px") 
    } else {
      return("120px")
    }
  })

Anyway it would be nice to have the input$sidebarCollapsed parameter in future releases of shinydashboardPlus, but for the moment it works as a nice workaround for me.