Inputs, Outputs, and Layouts

Mark Andrews

Expanding the toolkit

We now have the minimal app working. The next step is to understand the full range of available inputs and outputs, and how to lay them out in a usable interface.

Slider input

sliderInput("alpha", "Significance level",
            min = 0.01, max = 0.20,
            value = 0.05, step = 0.01)
  • min, max, value set the range and initial position
  • step controls the increment
  • Use for continuous numeric parameters

Select input

selectInput("dist", "Distribution",
            choices = c("Normal"      = "norm",
                        "Exponential" = "exp",
                        "Uniform"     = "unif"))
  • Named vector: the names are shown, the values are passed to input$dist
  • multiple = TRUE allows selecting more than one

Radio buttons

radioButtons("colour", "Point colour",
             choices = c("Blue" = "steelblue",
                         "Red"  = "firebrick",
                         "Grey" = "grey40"))
  • All options visible simultaneously
  • Appropriate when choices are few and comparison matters
  • Only one selection allowed at a time

Checkbox group

checkboxGroupInput("vars", "Variables",
                   choices = c("hp", "mpg", "wt"),
                   selected = c("hp", "mpg"))
  • Multiple selections allowed
  • input$vars returns a character vector of selected choices
  • Always use req(input$vars) before using the result

Matching render functions

# UI                          Server
plotOutput("p")        →   output$p <- renderPlot({...})
tableOutput("t")       →   output$t <- renderTable({...})
verbatimTextOutput("v")→   output$v <- renderPrint({...})
textOutput("x")        →   output$x <- renderText({...})

The ID string must match exactly — case-sensitive.

Multiple outputs in the main panel

mainPanel(
  plotOutput("scatter"),
  verbatimTextOutput("stats")
)

Outputs stack vertically by default. Use fluidRow / column for side-by-side arrangements.

Grid layout

fluidRow(
  column(8, plotOutput("scatter")),
  column(4, verbatimTextOutput("summary"))
)
  • Grid is 12 units wide; columns sum to 12
  • Can be nested inside mainPanel or at top level
  • Use for putting outputs side by side

helpText and wellPanel

sidebarPanel(
  wellPanel(
    h4("Simulation"),
    sliderInput("n", "Sample size", min = 50, max = 2000, value = 500),
    helpText("Larger samples take slightly longer to draw.")
  )
)
  • wellPanel groups related controls visually
  • helpText adds a grey explanatory note
  • Small additions with a large usability benefit

Connecting multiple inputs

output$hist <- renderPlot({
  x <- rnorm(input$n, mean = input$mean, sd = input$sd)
  hist(x, breaks = 30, col = "steelblue")
})
  • The render block depends on all three inputs
  • Changing any one of them triggers a redraw
  • Dependencies are tracked automatically — no registration needed

Summary

  • Each input widget type suits a different kind of user decision
  • Output type is determined by what you want to display
  • Sidebar layout is the standard starting point
  • Grid columns allow flexible side-by-side arrangements
  • Small additions (helpText, wellPanel) improve usability significantly