rshinysidebarcollapsable

R shiny collapsible sidebar


I have created the following application template in R shiny :

 library(shiny)
 library(shinyjs)

 ui <- fluidPage(
 useShinyjs(),
 navbarPage("",actionButton("toggleSidebar", "toggle", icon = 
 icon("database")),
          tabPanel("tab",
                  div( id ="Sidebar",sidebarPanel(
                  )),mainPanel() ))))


   server <-function(input, output, session) {
   observeEvent(input$toggleSidebar, {
   shinyjs::toggle(id = "Sidebar")
  }) }


 shinyApp(ui, server)

The App will create a toggle button in the sidebar. The button should appear in the navbar and not above the sidebar. The actual toggle button appears above next to the word tab. It is however, not visible.


Solution

  • The part that is not visible that you mention is in fact the empty title parameter that you have "". Leaving this out as below places the toggle button in the title position:

     library(shiny)
     library(shinyjs)
    
     ui <- fluidPage(
     useShinyjs(),
     navbarPage(actionButton("toggleSidebar", "toggle", icon = 
     icon("database")),
              tabPanel("tab",
                      div( id ="Sidebar",sidebarPanel(
                      )),mainPanel() )))
    
    
       server <-function(input, output, session) {
       observeEvent(input$toggleSidebar, {
       shinyjs::toggle(id = "Sidebar")
      }) }
    
    
     shinyApp(ui, server)