Layout a sidebar and main area — sidebarLayout

sidebarLayout(
  sidebarPanel,
  mainPanel,
  position = c("left", "right"),
  fluid = TRUE
)

sidebarPanel(..., width = 4)

mainPanel(..., width = 8)

Arguments

sidebarPanel

The sidebarPanel() containing input controls.

mainPanel

The mainPanel() containing outputs.

position

The position of the sidebar relative to the main area ("left" or "right").

fluid

TRUE to use fluid layout; FALSE to use fixed layout.

...

Output elements to include in the sidebar/main panel.

width

The width of the sidebar and main panel. By default, the sidebar takes up 1/3 of the width, and the main panel 2/3. The total width must be 12 or less.

Description

Create a layout (sidebarLayout()) with a sidebar (sidebarPanel()) and main area (mainPanel()). The sidebar is displayed with a distinct background color and typically contains input controls. The main area occupies 2/3 of the horizontal width and typically contains outputs.

See also

Other layout functions: fillPage(), fixedPage(), flowLayout(), fluidPage(), navbarPage(), splitLayout(), verticalLayout()

Examples

## Only run examples in interactive R sessions
if (interactive()) {
options(device.ask.default = FALSE)

# Define UI
ui <- fluidPage(

  # Application title
  titlePanel("Hello Shiny!"),

  sidebarLayout(

    # Sidebar with a slider input
    sidebarPanel(
      sliderInput("obs",
                  "Number of observations:",
                  min = 0,
                  max = 1000,
                  value = 500)
    ),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    )
  )
)

# Server logic
server <- function(input, output) {
  output$distPlot <- renderPlot({
    hist(rnorm(input$obs))
  })
}

# Complete app with UI and server components
shinyApp(ui, server)
}