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

  • ui.layout_sidebar
    ui.layout_sidebar(sidebar, *args, fillable=True, fill=True, bg=None, fg=None, border=None, border_radius=None, border_color=None, gap=None, padding=None, height=None, **kwargs)

  • ui.sidebar
    ui.sidebar(*args, width=250, position='left', open='desktop', id=None, title=None, bg=None, fg=None, class_=None, max_height_mobile=None, gap=None, padding=None)

No matching items

Collapsed sidebar

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

## file: app.py
from shiny import App, ui

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


def server(input, output, session):
    pass


app = App(app_ui, server)
from shiny.express import ui

with ui.sidebar(open="closed", bg="#f8f8f8"):  
    "Sidebar"

"Main content"
from shiny import App, ui

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


def server(input, output, session):
    pass


app = App(app_ui, server)

ui.sidebar() has an open parameter 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.