shiny.ui.layout_sidebar#

shiny.ui.layout_sidebar(sidebar, main, position='left')#

Layout a sidebar and main area

Create a layout with a sidebar (panel_sidebar()) and main area (panel_main()). The sidebar is displayed with a distinct background color and typically contains input controls. By default, the main area occupies 2/3 of the horizontal width and typically contains outputs.

Parameters
  • sidebar (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – A UI element to place in the sidebar (typically a panel_sidebar())

  • main (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – A UI element to place in the main area (typically a panel_main())

  • position (Literal[‘left’, ‘right’]) – The position of the sidebar (left or right)

Return type

A UI element

Example

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
from shiny import *
import matplotlib.pyplot as plt
import numpy as np

app_ui = ui.page_fluid(
    ui.layout_sidebar(
        ui.panel_sidebar(ui.input_slider("n", "N", min=0, max=100, value=20)),
        ui.panel_main(ui.output_plot("plot")),
    ),
)

def server(input: Inputs, output: Outputs, session: Session):
    @output
    @render.plot(alt="A histogram")
    def plot() -> object:
        np.random.seed(19680801)
        x = 100 + 15 * np.random.randn(437)

        fig, ax = plt.subplots()
        ax.hist(x, input.n(), density=True)
        return fig


app = App(app_ui, server)