A dashboard sidebar typically contains a sidebarMenu, although
it may also contain a sidebarSearchForm, or other Shiny inputs.
updateSidebar allows to toggle a dashboardSidebar on the client.
dashboardSidebar(
...,
disable = FALSE,
width = NULL,
collapsed = FALSE,
minified = TRUE,
id = NULL
)
updateSidebar(id, session = shiny::getDefaultReactiveDomain())Items to put in the sidebar.
If TRUE, the sidebar will be disabled.
The width of the sidebar. This must either be a number which specifies the width in pixels, or a string that specifies the width in CSS units.
If TRUE, the sidebar will be collapsed on app startup.
Whether to slightly close the sidebar but still show item icons. Default to TRUE.
Sidebar id.
Shiny session object.
if (interactive()) {
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(id = "sidebar"),
body = dashboardBody(
actionButton(inputId = "sidebarToggle", 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$sidebarToggle, {
updateSidebar("sidebar")
})
observe({
print(input$sidebar)
})
}
)
}