Learn R Programming

bs4Dash (version 0.5.0)

updatebs4Sidebar: Function to programmatically toggle the state of the sidebar

Description

Function to programmatically toggle the state of the sidebar

Usage

updatebs4Sidebar(inputId, session)

Arguments

inputId

Sidebar id.

session

Shiny session object.

Examples

Run this code
# NOT RUN {
if (interactive()) {
 library(shiny)
 library(bs4Dash)
 
 shiny::shinyApp(
   ui = dashboardPage(
     controlbar_collapsed = FALSE,
     controlbar_overlay = TRUE,
     navbar = dashboardHeader(),
     sidebar = dashboardSidebar(inputId = "sidebar"),
     body = dashboardBody(
       actionButton(inputId = "controlbarToggle", label = "Toggle Sidebar")
     )
   ),
   server = function(input, output, session) {
     
     observeEvent(input$sidebar, {
       if (input$sidebar) {
         showModal(modalDialog(
           title = "Alert",
           "The sidebar is opened.",
           easyClose = TRUE,
           footer = NULL
         ))
       }
     })
     
     observeEvent(input$controlbarToggle, {
       updatebs4Sidebar(inputId = "sidebar", session = session)
     })
     
     observe({
       print(input$sidebar)
     })
   }
 )
}
# }

Run the code above in your browser using DataLab