navigation

Introduction

Shiny lets us build interactive web apps, using R. This means we can use (pretty much) all of R’s extensive (and extensible) data analysis and visualisation features in our app. Essentially, we can take almost any analysis we’ve done in R, and then make it interactive. We can run our apps locally, within R Studio (this is what we’ll do most of today), make them standalone, either by deploying them to a Shiny Server, or to a hosting service, such as https://shinyapps.io (we’ll do this today), or even including them in a Markdown document.

R studio provide a gallery of other Shiny apps: https://shiny.rstudio.com/gallery/

Shiny works well with many widely used R packages, such as ggplot2, and Leaflet for R.

In this workshop, we’re going to use data from the Gapminder project to visualise how GDP per capita and life expectancy have changed over time. This takes one of Hans Rosling’s innovative visualisations and puts it into Shiny.

We’ll replicate this in Shiny (albeit without the smooth animation between years):

I’ve tried to minimise the amount of non-Shiny material in this workshop, but we will need to do some manipulation of the data. I’ve adopted a tidyverse based approach to doing this, using pipes and filters. If you’re more comfortable using base R you’re very welcome to use that approach. If you need a quick refresher on using the tidyverse to manipulate tabular data, this episode of the Data Analysis using R course, which we teach at the University of Manchester may be useful.

To minimise the amount of formatting of graphs etc, I’ve provided functions that will generate the graphs we’ll be using, given an appropriate data set. Where these functions are used you could use your own call to ggplot(), plot() etc.

How the course materials work

The bulk of the course consists of a single running example. We start with a “hello world” Shiny app, and gradually add features to it over the course. As you will be building on previous steps it’s possible that you will break your app, and be unable to fix it. If this happens, don’t panic; use your red sticky note to ask for help from one of the helpers.

You can download the course material as a zip file from here. You should decompress the zip file on your computer. It contains a series of numbered subdirectories. Each subdirectory corresponds to a “checkpoint” within the course.

If you are familiar with the git version control system, you may prefer to use this to navigate through the worked example. You can download the repository from https://github.com/UoMResearchIT/r-shiny-course-materials

Each checkpoint is a tagged commit, which you can checkout with:

git checkout tagname

(For example, git checkout 09_richcountry will take you to the finished app.)

You should checkout the initial commit, 00_workshopdata. This contains the data and functions we’ll be using.

Within this website, links to the commits are clickable, and will show you the diff of that commit on github.

If you would like to learn how to use git for version control, we offer a course on this. It makes managing your code much easier