Shiny App Structure Cheatsheet: Essential Quick Reference

Master the fundamentals with visual examples and ready-to-use code snippets

Complete visual reference guide for Shiny application structure covering UI/Server architecture, reactive programming, input/output patterns, and essential code templates for rapid development.

Tools
Author
Affiliation
Published

June 22, 2025

Modified

June 23, 2025

Keywords

shiny app structure, shiny cheatsheet, shiny quick reference, shiny ui server, R shiny tutorial

Shiny App Structure

Essential patterns and code snippets for rapid Shiny development

1 Basic App Structure

# Essential app.R structure
library(shiny)

# UI: What users see
ui <- fluidPage(
  titlePanel("My App"),
  sidebarLayout(
    sidebarPanel(
      # Input controls here
    ),
    mainPanel(
      # Output displays here
    )
  )
)

# Server: What app does
server <- function(input, output) {
  # Reactive logic here
}

# Run the app
shinyApp(ui = ui, server = server)

Quick Tip: Always save as app.R or use ui.R + server.R + global.R

2 Essential Input Controls

# Text input
textInput("name", "Enter name:")

# Numeric input
numericInput("num", "Number:", 
             value = 10, min = 1, max = 100)

# Slider
sliderInput("range", "Range:",
            min = 0, max = 100, value = 50)

# Select dropdown
selectInput("var", "Choose:",
            choices = list("A" = "a", "B" = "b"))

# Action button
actionButton("go", "Run Analysis")

Access Pattern

ìnput$name → Get text input value input$num → Get numeric input value input$go → Get button click count

3 Output Display Types

# UI side - what to display
plotOutput("myplot")
tableOutput("mytable")
textOutput("mytext")
verbatimTextOutput("mycode")

# Server side - how to create
output$myplot <- renderPlot({
  plot(cars)
})

output$mytable <- renderTable({
  head(cars)
})

output$mytext <- renderText({
  paste("Hello", input$name)
})

Remember: UI functions end with Output, server functions start with render

4 Reactive Programming

# Reactive expression
filtered_data <- reactive({
  cars[cars$speed > input$min_speed, ]
})

# Use reactive data
output$plot <- renderPlot({
  plot(filtered_data())  # Note the ()
})

# Observer (side effects)
observe({
  print(paste("Speed changed to:", input$min_speed))
})

# Event reactive (triggered by button)
analysis_result <- eventReactive(input$go, {
  # Expensive computation here
  lm(dist ~ speed, data = cars)
})

Reactive Flow

Input Changes → Reactive Expressions Update → Outputs Re-render

5 Common Layout Patterns

# Sidebar layout
sidebarLayout(
  sidebarPanel(# Controls),
  mainPanel(# Results)
)

# Tabbed layout
tabsetPanel(
  tabPanel("Plot", plotOutput("plot")),
  tabPanel("Table", tableOutput("table"))
)

# Grid layout
fluidRow(
  column(4, # Input column),
  column(8, # Output column)
)

Mobile Tip: Use fluidPage() for responsive design that works on all devices

6 File Organization

# Single file app
myapp/
  └── app.R

# Multi-file app
myapp/
  ├── ui.R          # UI definition
  ├── server.R      # Server logic
  ├── global.R      # Shared objects
  └── www/          # Static files
      ├── style.css
      └── logo.png

# Production app
myapp/
  ├── R/            # R functions
  ├── data/         # Data files
  ├── www/          # Web assets
  └── app.R

Best Practice

Use global.R for data loading and function definitions shared by UI and server



Ready to Build Your First Shiny App?

Master Shiny development with our comprehensive tutorial series

Start with Your First App Master Reactive Programming

From beginner to enterprise deployment • Step-by-step tutorials • Real-world examples

placeholder

placeholder
No matching items
Back to top

Reuse

Citation

BibTeX citation:
@online{kassambara2025,
  author = {Kassambara, Alboukadel},
  title = {Shiny {App} {Structure} {Cheatsheet:} {Essential} {Quick}
    {Reference}},
  date = {2025-06-22},
  url = {https://www.datanovia.com/learn/tools/shiny-apps/cheatsheets/app-structure.html},
  langid = {en}
}
For attribution, please cite this work as:
Kassambara, Alboukadel. 2025. “Shiny App Structure Cheatsheet: Essential Quick Reference.” June 22, 2025. https://www.datanovia.com/learn/tools/shiny-apps/cheatsheets/app-structure.html.