Slidify

Interactive Docs, UseR2014

Ramnath Vaidyanathan
McGill University

Slidify helps create, customize and share, elegant, dynamic and interactive HTML5 documents using R Markdown.

Install Slidify

Slidify is not on CRAN and needs to be installed from github using the devtools package. I would recommend installing the dev version of the package.

# install.packages('devtools')
pkgs <- c("slidify", "slidifyLibraries", "rCharts")
install_github(pkgs, 'ramnathv', ref = 'dev')

NOTE: While the installation process from github is relatively painless for Mac/Linux/Ubuntu users, it can make Windows users jump through hoops. For those of you on Windows that hit a bottleneck, here is an excellent blog post that takes you through an alternate installation process that has been reported to work well.

Slidify helps create, customize and share, elegant, dynamic and interactive HTML5 documents using R Markdown.

Quick Start

author("myDeck")
slidify("index.Rmd")
browseURL("index.html")
publish("myDeck", "ramnathv")

Create

The easiest way to get started is by using the author function to set up a scaffold for your slide deck. This will do the following

  • create a directory for the deck.
  • copy necessary scaffolding for the deck.
  • if you have git installed, then
    • initialize a git repo
    • switch to a gh-pages branch
    • commit all changes to the repo.
  • open index.Rmd for you to edit.

Setup

Your Turn

 ---
 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

Slidify

Your Turn

slidify("index.Rmd")
browseURL("index.html")

Slidify helps create, customize and share, elegant, dynamic and interactive HTML5 documents using R Markdown.

Customization

Slidify is highly modular and attempts to achieve clean separation of content from view and behavior. There are several ways to customize a document.

  1. Frameworks
  2. Layouts
  3. Widgets

We will look at customization in more detail later.

Slidify helps create, customize and share, elegant, dynamic and interactive HTML5 documents using R Markdown.

Share

Share on Github

The default option is to publish to github.

publish('myDeck', 'ramnathv')


In order to use this option, you need to

  • Install git.
  • Set up a github account.
  • Set up SSH access to github.

Alternately, you can also use the github GUI client to publish. This screencast provides details.

Share on Dropbox

You can share your deck using Dropbox, by copying it to your Public folder.

publish('myDeck', host = "dropbox")

You can also drag-and-drop your slide folder to your Public Dropbox folder and get a link to index.html. Press p to see a screenshot of how to do this.

Share on RPubs

RPubs is a service provided by RStudio to share RMarkdown documents. Here are the steps to share on RPubs.

  1. Change mode to standalone in index.Rmd.
  2. Slidify the deck slidify('index.Rmd').
  3. Hit Publish on the RStudio preview window.
  4. Follow the instructions from there.

Slidify helps create, customize and share, elegant, dynamic and interactive HTML5 documents using R Markdown.

Dynamic

Dynamic content implies that plots, tables and other results in the deck can be dynamically generated using code snippets. Slidify uses the knitr package to accomplish this.

 ## A Simple Plot

 ```{r simple-plot, fig.height = 6, fig.align = 'center', message = F}
 require(ggplot2)
 qplot(wt, mpg, data = mtcars)
 ```

 ---

 ## MotionPlot

 ```{r results = 'asis', commment = NA, message = F, echo = F}
 require(googleVis)
 M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")
 print(M1, tag = 'chart')
 ```

A Simple Plot

require(ggplot2)
qplot(wt, mpg, data = mtcars)

plot of chunk simple-plot

MotionPlot

Slidify helps create, customize and share, elegant, dynamic and interactive HTML5 documents using R Markdown.

Interactive

Slidify uses widgets to add interactive content to slides.

Your Turn

---
title: Interactive Quiz
widgets: [bootstrap, quiz]
--- &radio

## Question 1

What is 1 + 1?

1. 1 
2. _2_
3. 3

*** .hint

This is a hint

*** .explanation

This is an explanation

Question 1

What is 1 + 1?

  1. 1
  2. 2
  3. 3

This is a hint

This is an explanation

Interactive Chart

require(rCharts)
haireye = as.data.frame(HairEyeColor)
n1 <- nPlot(Freq ~ Hair, 
  group = 'Eye',
  data = subset(haireye, Sex == 'Male'),
  type = 'multiBarChart'
)
n1$show('inline')

Interactive Chart

How Slidify Works?

Credits

  1. Yihui Xie for knitr.
  2. Joe Cheng for Shiny.
  3. Jeffrey Horner and RStudio for R Markdown.
  4. Hadley Wickham for several R packages.
  5. Kenton Russel and Thomas Reinholdsson for coauthoring rCharts.
  6. Authors of all the JS Libraries I have liberally used.
  7. Authors of several presentation libraries in Ruby/Python/JS.