Ooh, Shiny!: R Shiny apps as a teaching tool

Interactive web applications (or apps), such as the Rossman-Chance collection, are popular tools for teaching statistics because they help illustrate fundamental concepts such as randomness, sampling, and variability through dynamic visualizations. The StatKey collection of apps created for the Lock5 textbook series to demonstrate and perform simulation-based inference is another example1. Historically, despite the utility of the web apps and the ease of their use, it was difficult for most stat educators to create or modify them because of the requisite coding knowledge in HTML, CSS, and Java/Javascript. Thankfully, RStudio created the R package {shiny}, which allows web apps (i.e., Shiny apps) to be created using R code alone, and the HTML/CSS/Javascript work is done by the package “behind the scenes”.

The fundamental idea behind Shiny apps is the division of labor between the user interface (or UI, for short) and the server. The UI is created with input options such as sliders, drop-down menus, and other widgets that the user manipulates. Then, a server running R in the background dynamically updates the certain outputs on the webpage (i.e., graphs, tables, etc.) that depend on these inputs. For instance, this simple histogram app updates a histogram of geyser eruption duration data based on a user-supplied number of bins.

My thoughts about Shiny

My opinion is that Shiny is a fun tool that draws students in. (The term “Shiny” is quite apt in that sense2.) Students are used to absorbing information through dynamic web content on their devices, and Shiny provides us with a tool to meet them at that level. I have used Shiny apps as part of in- or out-of-class assignments and as lecture/video supplements.

I’ve created the Happy Apps collection3 (with source code) for teaching intro statistics. (Thanks to Danny Kaplan for hosting these.) I’d love to hear your feedback about them!

Resources for learning Shiny

Shiny is no longer brand new (or, “shiny-new”)4, so there are a multitude of resources available for learning Shiny, including RStudio’s Shiny homepage. My personal introduction was through this excellent video series by Garrett Grolemund, but the RStudio Shiny site contains two other written tutorials as well: Building Web Applications with Shiny and Shiny in seven lessons.

RStudio also maintains a gallery of user contributions and demos that highlight specific features of Shiny. Many of the apps in the showcase are winners from the annual Shiny contest, which began in 2019.

A more comprehensive resource is Mastering Shiny, a free online book by Hadley Wickham. It starts with learning Shiny “from scratch” (like these other tutorials), but provides more foundational instruction useful for making more advanced apps. There are also a multitude of articles on the RStudio Shiny website covering individual Shiny topics at a more advanced level.Of course, there a variety of other resources for learning Shiny throughout the web5, but I find the RStudio resources to be the most comprehensive and organized.

Collections of Shiny apps

“Shiny gives you the ability to pass on some of your R superpowers to anyone who can use the web.”

Hadley Wickham, Mastering Shiny, Preface (0.1)

In this section, I highlight some of those who have passed on their “superpowers” in the service of statistics education. For one, Bernhard Klingenberg has impressively created a collection of apps to accompany almost every topic in the intro stats book The Art & Science of Learning from Data (coauthors Alan Agresti and Christine Franklin)6. Also, one of the earliest collections of Shiny apps was introduced in a 2016 TISE paper that was referenced in the GAISE report. In addition, Danny Kaplan has developed a collection of Little Apps, which are “tools for teaching and learning statistical concepts in a data-centric way”7 Further, Mine Çetinkaya-Rundel has a collection she calls ShinyEd.

Shiny apps are also a nice opportunity for undergraduate research, as some recent programs have demonstrated. Dennis Pearl’s BOAST program (BOAST = Book Of Apps for Statistics Teaching) at Penn State has had 10 students take part in a full-time summer research experience developing apps each year since 2017. In the BOAST program, students work in teams and with faculty mentors, both on debugging and improving the apps developed the previous summer and in developing new apps. Following this model and inspiration, Maria Tackett jumpstarted the Duke ShinyEd program in summer 2020.

I know I’ve left out many existing Shiny app collections, so please respond to this post with app links to share.

Methods of deploying Shiny apps

Locally

First, the simplest way to run a Shiny app is to run it on your local computer. This method should not be overlooked because it bypasses the issue of setting up an external server. Download the R code for the app to your local computer, open the app.R or ui.R/server.R file in RStudio and click the “Run App” button. My intro stats class that uses R runs my Shiny apps in this way. However, it would require some practice if your class is not using R.

For instance, this could be used to access many of the apps on my Github page that aren’t hosted as part of the Happy Apps collection. One called steps is an example-driven tutorial on learning to code Shiny apps.

Services from RStudio

RStudio provides shinyapps.io as an easy way to publish Shiny apps and have users operate them from a browser. RStudio provides different levels of service, including a free version with limits of 5 apps and 25 active hours per month. Unfortunately, the latter is quite limiting as a class of 25 students each using an app for one hour would already bring you to your monthly limit. There are pay plans offering more apps and more active hours. However, “The service is not competitively priced if you only look at the computing power for your cash,” according to this post on R-bloggers, but this may not apply for educational needs8.

See this page for a summary of all of RStudio’s hosting and deployment services.

Make friends with your IT department

Another option is to set up a server at your institution. (This is beyond the capability of most stat educators, so relies on the work of your IT department.) RStudio offers Shiny Server Open Source, free code to set up a server for Shiny apps. We had one set up at GVSU until it was taken down due to concerns that Shiny apps did not meet web accessibility standards.

Last, citing concerns about computational delays in Shiny Server Open Source, this article describes how to employ ShinyProxy, a solution from OpenAnalytics.

Contributing author Dan Adrian is an Associate Professor of Statistics at Grand Valley State University.

Footnotes

1Other examples of apps are the Distributome, which is part of the SOCR, Seeing Theory, and Rock ’n Poll. (Click each link to learn more.)

2Though the colloquial meaning of “shiny” often refers to distraction, I think Shiny apps have the ability to be attention-holding as well.

3a take off on R.E.M.’s song Shiny Happy People

4According to this R-bloggers post, RStudio’s Joe Cheng first announced Shiny to beta testers at the JSM 2012 conference.

5for instance, see a tutorial by ZevRoss or this post on the towards data science blog

6Bernhard also has a Youtube Channel where he talks through the concepts associated with many of these apps while he demonstrates their operation.

7The Little Apps were developed as part of the StatPREP initiative and have a set of accompanying documents about how instructors have used the apps in their classes.

8If more computing power is required, RStudio offers RStudio Connect; the previously offered Shiny Server Pro is no longer being offered to new customers.

2 thoughts on “Ooh, Shiny!: R Shiny apps as a teaching tool

Add yours

    1. Thanks! I must confess I’m not very familiar with licensing. Basically, I would like the code to be publicly available but ask that others cite my work where appropriate. Does that make sense?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: