Workflow

Lecture 23

Dr. Eric Friedlander

College of Idaho
CSCI 2025 - Winter 2026

Development Workflow

Creating and Running

  • Creation:
    • One file app: app.R
    • Two file app: ui.R and server.R
  • In RStudio/Positron:
    • Click the Run App button (play icon) in the toolbar.
  • Stopping:
    • Click the Stop sign in the console.

Shiny Skeleton

library(shiny)
ui <- fluidPage(
)
server <- function(input, output, session) {
}
shinyApp(ui, server)

Debugging

Three Types of Problems

  1. Unexpected Error: You get a traceback.
    • Easiest to fix.
  2. Incorrect Value: No error, but wrong result.
    • Requires investigation (browser()).
  3. Incorrect Logic: Updates happen at wrong time (or not at all).
    • Hardest. Unique to Shiny’s reactivity.

Tracebacks and browser()

  • Traceback: Read from bottom to top to find your code.
  • browser():
    • Place browser() inside your server function.
    • Execution pauses when it hits that line.
    • You can inspect input, output, and intermediate variables in the console.
server <- function(input, output, session) {
  observeEvent(input$go, {
    browser() # Execution pauses here
    # Inspect input$x, calculated values, etc.
  })
}

Debugging Reactivity

  • Reactivity is lazy and non-linear.
  • Code doesn’t run top-to-bottom.
  • Visualizing the Reactive Graph helps.
  • Use message() inside reactive() to verify:
    1. Is it running?
    2. Is it running too often?
    3. Is it running in the expected order?

Getting Help

The Reprex

  • Reprex: Reproducible Example.
  • Critical for getting help (StackOverflow, RStudio Community).
  • Properties:
    • Minimal: Remove everything not related to the bug.
    • Self-contained: Copy/pasteable. runs on anyone’s machine.
      • No read.csv("C:/MyFiles/data.csv").
      • Use code to generate dummy data.

Creating a Shiny Reprex

  1. Isolate the problem (remove unrelated UI/Server code).
  2. Use built-in datasets (e.g., mtcars).
  3. Combine UI and Server in one file.
library(shiny)

ui <- fluidPage(
  numericInput("n", "N", 5),
  textOutput("txt")
)

server <- function(input, output, session) {
  output$txt <- renderText(input$n * 2)
}

shinyApp(ui, server)

Practice!

Let’s work through the case study in the text!

Summary

Workflow Tips

  • Read tracebacks carefully.
  • Use browser() to stop and inspect.
  • Use message() to track reactive execution.
  • When stuck, create a Reprex.

Do Next

  1. Read Chapter 5: Workflow from Mastering Shiny.
  2. There’s NO recitation Gem for this textbook but I recommend creating your own and adding the textbook chapter and these slides.
  3. I reommend working through the Exercises in the textbook.
  4. Move on to Lecture 23!