Introducing learnr

We’re pleased to introduce the learnr package, now available on CRAN. The learnr package makes it easy to turn any R Markdown document into an interactive tutorial. Tutorials consist of content along with interactive components for checking and reinforcing understanding. Tutorials can include any or all of the following:

  • Narrative, figures, illustrations, and equations.

  • Code exercises (R code chunks that users can edit and execute directly).

  • Multiple choice quizzes.

  • Videos (supported services include YouTube and Vimeo).

  • Interactive Shiny components.


Each learnr tutorial is a Shiny interactive document, which means that tutorials can be deployed all of the same ways that Shiny applications can, including locally on an end-user’s machine, on a Shiny or RStudio Connect Server, or on a hosting service like

Getting Started

To create a learnr tutorial, install the learnr package with


Then select the Interactive Tutorial template from the New R Markdown dialog in the RStudio IDE (v1.0.136 or later).



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

To add an exercise, add exercise = TRUE to the chunk options of an R Markdown code chunk. R Markdown will preload the chunk with the code that you supply.

```{r ex1, exercise = TRUE}
head(mtcars, n = 5)



Exercises can include hints or solutions as well as custom checking code to provide feedback on user answers. The learnr Exercises page includes a more in depth discussion of exercises and their various available options and behaviors.


You can include one or more multiple-choice quiz questions within a tutorial to help verify that readers understand the concepts presented. Questions can have a single or multiple correct answers.

Include a question by calling the question() function within an R code chunk:

```{r letter-a, echo=FALSE}
question("What number is the letter A in the English alphabet?",
  answer("1", correct = TRUE),



You can include videos published on either YouTube or Vimeo within a tutorial using the standard markdown image syntax. Note that any valid YouTube or Vimeo URL will work. For example, the following are all valid examples of video embedding:



Code checking

learnr works with external code checking packages to let you evaluate student answers and provide targeted, automated feedback, like the message below.


You can use any package that provides a learnr compatible checker function to do code checking (the checkr package provides a working prototype of a compatible code checker).

Each learnr tutorial includes a Table of Contents that tracks student progress. learnr remembers which sections of a tutorial a student completes, and returns a student to where they left off when they reopen a tutorial.


Progressive Reveal

learnr optionally reveals content one sub-section at a time. You can use this feature to let students set their own pace, or to hide information that would spoil an exercise or question that appears just before it.

To use progressive reveal, set the progressive field to true in the yaml header.

title: "Programming basics"
    progressive: true
    allow_skip: true
runtime: shiny_prerendered

Visit to learn more about creating interactive tutorials with learnr.

More On Products and Technology

Stay Connected

Get updates when there's a new post.