Key Points

Introduction to Shiny


  • A Shiny app is an R program that generates interactive web content.
  • A Shiny app has three required parts: a user interface, a server function, and a call that runs the app.
  • The user interface defines what the app looks like, while the server defines how it behaves.
  • Shiny works by generating HTML in R, which is rendered by a web browser.

The Basics of a User Interface


  • The user interface (UI) defines what appears in a Shiny app.
  • UI elements are created using ordinary R functions provided by Shiny.
  • Many UI functions generate HTML elements that are rendered by a web browser.
  • Layout functions define the overall structure of the app, while other UI functions define the content placed within that structure.

Inputs and Outputs


  • Shiny apps become interactive by connecting user inputs to server logic that produces outputs.
  • Inputs are defined in the UI using *Input() functions and accessed in the server through the input list.
  • Outputs have placeholders in the UI created with *Output() functions and are generated in the server using matching render*() functions.
  • Code inside a render*() function is re‑run automatically when the input values it depends on change.
  • Server logic controls how user input is translated into displayed output.

Organising Server Logic with Reactive Expressions


  • Reactivity is central to how Shiny apps update in response to changes in user input.
  • Code inside render*() functions is automatically re‑run when its reactive dependencies change.
  • Repeating the same data preparation logic across multiple outputs can make apps harder to maintain.
  • reactive() expressions allow shared server logic to be computed once and reused across multiple outputs.

Making Shiny Apps Public


  • A Shiny app must be hosted on a service capable of running R.
  • shinyapps.io provides a simple way to publish Shiny apps.
  • The same Shiny concepts can be used to build more complex applications.

Bonus: Extending your Shiny App


  • Shiny apps can be extended by modifying the same user interface, server, and reactive patterns used to build the original app.
  • New app features often require changes in both the user interface and server code.
  • Reactive expressions can be reused when adapting an app to work with different variables or datasets.
  • Once you understand the basic structure of a Shiny app, it is often straightforward to adapt it to answer new questions.