Interactive Apps with Shiny

Shiny is an R package for building interactive web applications, pairing a UI that defines inputs and outputs with a reactive server that recomputes results automatically whenever a user changes an input.

Learn Interactive Apps with Shiny in our free R course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.

Part of the free R course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

By the end of this lesson you'll understand the ui/server split, the reactive model, how inputs and outputs connect, and how to build and launch a small interactive app with shinyApp().

What You'll Learn in This Lesson

1️⃣ The Three Parts of an App

Every Shiny app is a ui (the layout the user sees), a server function (the R logic), and a call to shinyApp() that launches them together. Inputs in the UI carry an inputId ; the server reads them via input$id and writes results to output$id .

2️⃣ Inputs, Outputs, and Reactivity

Inputs such as sliderInput() send values to the server; render*() functions like renderPlot() compute results, which a matching *Output() placeholder displays. Because Shiny is reactive , any output that mentions input$bins automatically re-runs when the slider moves — no manual refresh.

3️⃣ Sharing Work with reactive()

When several outputs need the same intermediate value, wrap it in reactive() . The expression runs once per change and caches its result, so a plot and a summary can share one data set instead of computing it twice. You access a reactive by calling it like a function: sample_data() .

Your turn. Fill in the # TODO lines, then run the app in RStudio.

Build a complete small app from the outline: two numeric inputs, a shared reactive() , and a text output. It ties together everything in this lesson.

📋 Quick Reference — Shiny

Practice quiz

What are the three parts of every Shiny app?

  • model, view, controller
  • head, body, footer
  • ui, server, and a shinyApp() call
  • input, output, plot

Answer: ui, server, and a shinyApp() call. A Shiny app is a ui object, a server function, and a shinyApp() launcher.

What is the job of the ui object?

  • Run calculations
  • Describe inputs and output placeholders the user sees
  • Connect to the database
  • Start the web server

Answer: Describe inputs and output placeholders the user sees. The ui defines layout, inputs, and output slots; it does no computation.

How does the server read a value from an input with id 'name'?

  • get("name")
  • ui$name
  • input$name
  • server$name

Answer: input$name. Inputs are read via input$id inside the server.

Where does the server write results so the UI can show them?

  • input$id
  • render$id
  • ui$id
  • output$id

Answer: output$id. The server assigns rendered results to output$id.

What does 'reactive' mean in Shiny?

  • Outputs auto-recompute when their inputs change
  • Code runs top to bottom once
  • The UI polls the server every second
  • Errors are retried automatically

Answer: Outputs auto-recompute when their inputs change. Shiny re-runs only the outputs that depend on a changed input, with no manual loop.

Which function pairs with plotOutput() to draw the plot?

  • drawPlot()
  • renderPlot()
  • plotRender()
  • makePlot()

Answer: renderPlot(). renderPlot() computes the plot that plotOutput() displays.

When should you use reactive()?

  • To build the UI layout
  • To launch the app
  • To share or cache an intermediate value across outputs
  • To install packages

Answer: To share or cache an intermediate value across outputs. reactive() runs once per change and caches, so multiple outputs reuse the result.

How do you access the current value of a reactive named sample_data?

  • sample_data()
  • sample_data$value
  • get(sample_data)
  • $sample_data

Answer: sample_data(). You call a reactive like a function: sample_data().

Which call launches a Shiny app?

  • runApp(ui)
  • launch(server)
  • shinyApp(ui, server)
  • start(ui, server)

Answer: shinyApp(ui, server). shinyApp(ui, server) wires the two parts together and starts the app.

Why can't a Shiny app run on a one-shot snippet website?

  • It needs a paid license
  • Shiny is a live web server needing a running R process and browser connection
  • Snippet sites block the shiny package
  • It only runs on Windows

Answer: Shiny is a live web server needing a running R process and browser connection. Shiny apps host a live server with a browser connection, which snippet sites cannot provide.