Sidebars

A sidebar layout creates a sidebar in your Shiny app, typically used for inputs, and a large main area, typically used for outputs.

A sidebar layout creates a sidebar, typically used for inputs, and a large main area, typically used for outputs.

Relevant Functions

  • page_sidebar
    page_sidebar(..., sidebar = NULL, title = NULL, fillable = TRUE, fillable_mobile = FALSE, theme = bs_theme(), window_title = NA, lang = NULL)

  • sidebar
    sidebar(..., width = 250, position = c("left", "right"), open = NULL, id = NULL, title = NULL, bg = NULL, fg = NULL, class = NULL, max_height_mobile = NULL, gap = NULL, padding = NULL)

  • layout_sidebar
    layout_sidebar(..., sidebar = NULL, fillable = TRUE, fill = TRUE, bg = NULL, fg = NULL, border = NULL, border_radius = NULL, border_color = NULL, padding = NULL, gap = NULL, height = NULL)

No matching items

Collapsed sidebar

#| standalone: true
#| components: [viewer]
#| layout: horizontal
#| viewerHeight: 125

## file: app.R
library(shiny)
library(bslib)

ui <- page_sidebar(
  sidebar = sidebar("Sidebar", bg="#f8f8f8", open = "closed"),
  "Main content"
)

server <- function(input, output) {

}

shinyApp(ui = ui, server = server)

sidebar() has an open argument that defines whether the sidebar appears open or closed when the app launches. To create a sidebar that is initially closed, set the open parameter to "closed".

The other options for open are:

  • "desktop": The default. The sidebar starts open on a desktop screen and closed on mobile.
  • "open": The sidebar starts open and can be closed.
  • "always": The sidebar is always open and cannot be closed.