Marco Sciaini

Creating a presentation with R

21 Jun 2015

Slidify

As a LaTeX fan, I started early to write my presentations with the Beamer document class. Unfortunately, the default classes are starting to look rather antique today and lack the possibility to implement a lot of cool stuff, like maps from leaflet and other applications. This is why the search for something different began.

The first alternative I stumbled upon was io2012 slides, an HTML/JavaScript framework for Google I/O 2012. As you may have heard, it's kind of awesome. Another framework that deserves recognition is definitely reveal.js, which has a solid balance between looking sleek but also very modern. While they look like nice solutions they also require decent web development skills to take advantage of them.

R offers two packages to create presentations with HTML/JavaScript frameworks without actually knowing anything about Java or HTML. There is the package slidify from Ramnath Vaidyanathan and there is R presentation, a feature of RStudio. They both function as a wrapper of several libraries which allows you to go from simple R Markdown to HTML presentations.

I decided to go with slidify because it looked more customizable and offered more JavaScript frameworks. During the first "experimentations" the look of the io2012 slides felt quite comfortable to me and so R presentation was no option. If this has changed in the meantime, please e-mail me with your experience or post something in the discussion.

It seems that slidify is becoming a "thing" now, which is why I will restrict myself to show just the basics of the package and refer to some useful links.

But first have a look at an example by frederickf:

1. Install and Initialize

As stated out by Ramnath, the author of the package, slidify is still under heavy development. Therefore, we have to install it from github using the devtools package:

install_github('slidify', 'ramnathv')
install_github('slidifyLibraries', 'ramnathv')

After installing and loading slidify you can run:

author("Presentation")

... to initialize a presentation. The function will create a directory for the deck, copy necessary scaffolding for the deck (assets and libraries) and open a default R markdown file:

---
title       :
subtitle    :
author      :
job         :
framework   : io2012        # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js  # {highlight.js, prettify, highlight}
hitheme     : tomorrow      #
widgets     : []            # {mathjax, quiz, bootstrap}
mode        : selfcontained # {standalone, draft}
knit        : slidify::knit2slides
---

## Read-And-Delete

1. Edit YAML front matter
2. Write using R Markdown
3. Use an empty line followed by three dashes to separate slides!

--- .class #id

## Slide 2

The code between the two sets of three dashes is the YAML front matter (a recursive acronym that stands for "YAML Ain't Markup Language"), which is used to control the underlying layout and initialize the presentation.

The deck can be shared using GitHub, Dropbox or RPubs directly from R.

2. Author and Edit

As I pointed out, here just some basics on how to control slidify:

2.1 Add slide content

With three dashes we can separate slides. Content can be written in Markdown or plain HTML. R Code can be implemented like this:

```{r}
# imagine random code here
```

2.1 Change the look and feel

To change the look and feel of your presentation the options framework, highlighter and hitheme must be changed. For each of them a variety of options are available:

A short summary of all of this is shown in Ramnaths video about slidify:

3. Generate and Publish

To generate a static HTML file containing the presentation we can just use:

slidify("index.Rmd")

... and have a look with:

browseURL("index.html")

Github and Dropbox can be accessed with:

# replace USER and REPO with your username and reponame
publish(user = "USER", repo = "REPO", host = 'github')

... and:

publish('mydeck', host = 'dropbox')

4. Summary

It looks great. It plays nice with shiny and rCharts. It can easily be published on github. There’s a tonne of cool things slidify can do and I am sure I haven't discovered all of them.

Printing to PDF is a challenge, but I have not checked all options yet (like pandoc for example) This is probably the only downside I came across with during the making of my first HTML presentation.

Overall, the combination of Markdown and slidify can create a nice set of slides in a short amount of time. The coding with slidify is very straightforward and feels fresh after using Beamer for a long time. If you use R frequently, slidify helps by bringing together reproducible analysis and a nice presentation of your results.