Shiny Tutorials

Shiny is an R package that allows R users to create interactive web applications without needing to write any HTML, JavaScript or CSS. Building the most basic Shiny apps does not require that much practice or training, however Shiny apps can quickly become more complex and advanced as the list of desired features for your app increases. Advanced functionality typically comes under the following headings:

  • Customising appearance of individual elements (colours, size and shape of elements)
  • Customising the behaviour of controls (update control X when control Y is updated)
  • Preventing updates unless a specific control has been changed (do not re-draw a map entirely unless X is changed)
  • Remove/add controls or outputs in a Shiny app dependent on a control

This OxShef website contains a number of tutorials but should not be considered a resource that will get you from never using Shiny before to building advanced Shiny apps with all of the features above. The following external resources on Shiny are highly recommended:

All tutorials assume you are using RStudio for writing R code. RStudio provides a number of features that make it generally easier to develop Shiny apps than using the R Console.

Shiny 101

The Shiny 101 tutorial introduces the very basics of a Shiny app by teaching you how to build the app you can see embedded here.

The code for this app is on the Github repo and the app is embedded into this page using a simple iframe, see here for more details.

Controls dependent on data

Oftentimes controls should be dependent on the data being visualised, for instance restricting a list of countries from a dataset to a specific continent - selected by the user. This is slightly more complicated that you might initially imagine, as the ui.R file is by definition ignorant of any values from the server.R other than what is provided on the output object via render* functions.

The following example app is explained in this tutorial. It makes use of the gapminder and rnaturalearthhires library to introduce the basics of both interdependent and data dependent controls. The code for this Shiny app is on the Github repo and the Shiny app is embedded into this page using a simple iframe, see here for more details.

<!– # Shiny and htmlwidgets

OxShef Specific Features/Customisations

There are a number of features/customisations made to the OxShef Shiny templates, these tutorials introduce how each of them work separately.

Flashing and disappearing “loading data”

This does require some CSS

Optional “Popout button” in menubar