A couple of days ago I taught a workshop on data visualization with ggplot2. For these kinds of workshops —i.e. code-heavy classes that rely on the application software tools—course websites are a useful tool. They give you as an instructor a central place where students can access installation instructions, your slides, and most importantly, code examples from your slides. But often, code examples in the presentation are spread over many slides, making it difficult for students to find them, even if you give them the slides.

RStudio has features to build websites and author presentations in rmarkdown. This makes it easy to generate a simple course websites and to build presentations which contain a lot of code.

But is it possible to generate website content from the slides directly? Such a dynamically generated website would allow a teacher to prepare slides for presentation in the classroom and easily accessible reference material (i.e. navigation menus or downloadable markdown scripts) on the course website, at the same time, saving you a lot of time.

To see what I mean, see the example from the course website I built this way:

Spoiler: of course it possible.

Unfortunately, I ran into some annoying hiccups while putting my integrated presentation/course website together, so I thought a walkthrough might be useful to save other instructors some unnecessary headaches.

1st Step: Set up a course website

You create a new folder for the course website and set up an RStudio project (see this article for more on why you should use RStudio projects). In this folder, you create a basic rmarkdown website following these steps..

2nd Step: Create presentation

Within this website folder you generate a new folder called ./presentation/ (yes, more useful names are allowed). Inside this folder you create a new project for the presentation only. It might possible to integrate everything, the website and the presentation, into one project. I like to keep things separate, though (you also might run into some problems with the different rendering engines).

Now you can happily start creating slides.

Side note: rmarkdown presentation engines

Which engines should you use for authoring rmarkdown presentations? RStudio ships with a number of different flavors:

  • ioslides
  • Beamer
  • reveal.js
  • Slidy

They all have their advantages and disadvantages, and to be honest, I didn’t test the process I’m describing here with all of them. In theory, they should work equally well, since they’re all based on pandoc to translate rmarkdown into HTML or PDF. But in practice, they sometimes have some different flavor of markdown, which makes it difficult to convert them into the HTML needed for the website.

The engine that I ended up using is called xaringan. There is no particular reason why I chose this other than that it looks nicer than the engines provided by RStudio. A more comprehensive list why xaringan is pretty good can be found on this post by the package author Yihui Xie.

Please note that remark.js does not support Pandoc’s Markdown, so you will not be able to use any fancy Pandoc features, but that is probably fine for presentations.

3rd Step: Create