Using learnr to build an interactive R tutorial

Sep 16, 2017 16:25 · 297 words · 2 minutes read R tidyverse learnr

In June 2017, I joined a major Canadian bank as a data analyst. I was suprised that most of my colleagues didn’t use R or Python for their day-to-day data analysis. I’ve been convincing my colleagues that R and Python are great tools for data analysis and trying to give an introduction on these two programming languages.

Last week I saw a post about learnr package on RStudio Developer Blog and I believed this package would be a great tool to create an interactive R tutorial for my team. Then in the following weekend, I created a little R tidyverse tutorial based on learnr and shared it with my teammates on shinyapp.io.

Building interactive tutorials for R

The learnr package makes it easy to turn any R Markdown document into an interactive tutorial. My tutorial is actually a R Markdown file including following content:

1. Exercise

Exercises in learnr are interactive R code chunks that allow readers to directly execute R code and see it’s results:

Exercise examples Exercises can include hints or solutions as well as custom checking code to provide feedback on user answers.

2. Questions

One or more multiple-choice quiz questions can be included within a tutorial to help verify that readers understand the concepts presented. Questions can either have a single or multiple correct answers. You can also add answer-specific correct/incorrect messages.

Quetion example

Quetion example

3. Video

Sometimes you may think it’s easier to explain a complex concept by video than words. learnr allows you to include video published on either Youtube or Vimeo within a tutorial using the standard markdown image syntax.

4. Publishing

Tutorials can be published all of the same ways that Shiny applications can, including running locally on an end-user’s machine or running on a Shiny Server or hosting service like shinyapp.io.