Introduction to Shiny
From the logic of Shiny to your app online
Shiny lets you turn R code into an interactive web application: the user clicks, chooses and uploads, and R does the computations behind the scenes.
In this course we start from an empty RStudio project and finish with your own app online, with a link you can send to anyone.
The plan
Day 1 · The logic of Shiny
| Topic | What you take home |
|---|---|
| Shiny | What Shiny is and the logic behind it: UI, server and their communication |
| A Shiny project | An RStudio project with ui.R and server.R that runs |
| How Shiny thinks | Inside the UI and the server: IDs and reactivity |
| Input widgets | What each widget sends to the server |
| Outputs and render functions | How results go back to the UI |
Reactivity and reactive() |
When the server re-runs your code |
Wait for it: eventReactive() |
Deciding when the app reacts |
| Your app: explore a dataset | A complete app, built step by step |
Day 2 · Spread the shine
| Topic | What you take home |
|---|---|
| Your app on GitHub | The project in a GitHub repository |
| Deploy on Connect Cloud | Your app online |
Going further collects the topics we will not cover in class (layouts, updating inputs, interactive plots, downloads), with working apps you can study on your own.
Before the course
Install R and RStudio Desktop (recent versions)
Install the packages we need:
install.packages(c("shiny", "rsconnect"))Create a free GitHub account and install GitHub Desktop
Create a free account on Posit Connect Cloud, signing in with your GitHub account
How to use these pages
Most examples are live apps that run in your browser. Each app is shown twice:
- first the app alone: play with it and see what it does
- then its code (
ui.Randserver.Rin two tabs), with the explanation and the same app running below it
- You can edit the code and re-run the app with the ▶ button (or Ctrl-Shift-EnterCtrl-Shift-Enter)
- Nothing you do here can break anything: reload the page to start over
- The first app on a page takes a few seconds to start (R is being loaded in your browser)
All the apps of the course are in the apps folder of the repository. Each app is a folder with a ui.R and a server.R file.