Shiny: Render R Plots into Interactive HTML
Following strong, long-standing recommendations from friends (Chris Meaney) and colleagues (Anna Nicanorova), I recently had the pleasure of building an interactive HTML interface using the R Shiny package for a commercial project.
The concept is brilliant. Shiny enables you to output any of your favourite R graphics from a web browser so that you can easily share visualisations of your data or results, such as this plot of film ratings with Oscar winners shown in gold:
The Shiny developers, RStudio, provide a set of "control widgets" you can add to the output HTML so that viewers of your output can adjust parameters of the plot. In the film ratings example above, this includes:
- a slide to select a "minimum number of reviews" threshold,
- a double-sided slider to choose a range of release years, and
- a drop-down box to select film genre.
Here are some of the most widely useful control widgets:
As a frequent R programmer, I found the implementation of Shiny to be straightforward. You need to get used to working simultaneously with two separate R files (server.R for backend calculations and ui.R for the user interface), familiarise yourself with the available control widgets, and discover reactive functions (reactivity enables the graphics to respond to live user input), but the well-produced tutorials make this process easy and fun.
RStudio provide a gallery full of beautiful examples (including their underlying code), but another one of my favourites is this map of the United States that has demographic data you can explore by postal (ZIP) code:
If you're looking to provide someone, perhaps a client, with an enjoyable way to explore their own data or to share the results of your work for them, I can now corroborate Shiny as a great way to do it! It could also make for a fun way to tell a data story during a presentation.
Nice!