Slidify

This is an R Markdown document created with examples of how to work with slidify. Based on Coursera’s Data Products course.


About slidify

  • Slidify allows you togGenerate reproducible html5 slides from R markdown
  • It is is an almagamation of other technologies including knitr, Markdown, and several javascript libaries
  • It allows embedded code chunks and mathematical formulas
  • You can view sllidify presentations with any web browser and share them easily on Github, Dropbox, or your own website

You need to install it and load it

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

Start a new slidify document:

Set the working directory to where you want to create your Slidify project

setwd("./projects/")

Create your project and give your project a name (My project is named “example_project”)

library(slidify)
author("example_project")

Then, automatically:

  1. A directory with the name of your project is created inside of your current directory.
  2. Inside of this directory an assets directory and a file called “index.Rmd” is created.
  3. The assets directory is populated with the following empty folders: css, img, js, and layouts.
  4. The newly created index.Rmd R Markdown file will open up in RStudio.

The content of the slides should be included in the index.RMD file, which looks like this:

  • index.Rmd is the R Markdown document which you will use to compose the conent of your presentation.
  • The first part of an index.Rmd file is a bit of YAML code which will starts with a header like this:
---
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}
---

You can fill in your title, subtitle, author name and job, save index.RMD and type

slidify('index.Rmd')

That creates an index.html file which is composed of slides! You could also use the knitr html on Rstudio. ```

Options that one may set up

Let’s look once again at the (so-called YAML, which stands for yet another markup language) that the index.Rmd file beings with (now I filled it a bit):

---
title : My title
subtitle : My subtitle
author : Obviously me
job : Doing stuff
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
widgets     : [mathjax, quiz, bootstrap, interactive]            # {mathjax, quiz, bootstrap}
mode        : selfcontained # {standalone, draft}
knit        : slidify::knit2slides
ext_widgets: {rCharts: [libraries/nvd3]}
---

The framework accounts for the formatting. As you see, there are several options besides io2012. Highlighter accounts for some of the effects. Widgets allow you do include stuff (mathjax allows you to include Latex code, which you can put it in between 2 dollar signs or 2 pairs of dollar signs; quiz allows you do do quizes as we will see). The mode should be chosen taking into account whether or not you will have internet access when you want to display the slides. The rcharts “ext_widget” allows including rcharts. This is what the first page of the slidified document will look like:

simplestApp

Quizes

If you type

--- &radio

## Question 1

What is 1 + 1?

  1. 1
  2. _2_
  3. 3
  4. 4

*** .hint This is a hint

*** .explanation This is an explanation

you get an interactive question:

simplestApp

  • The &radio added to the slide separator instructs slidify to use the radio template, which ships with the quiz widget.
  • The answer is marked up by enclosing it within underscores.
  • The hint and the explanation are preceded by three stars and a dot, which instruct slidify to parse them as blocks, that will be made use of by the radio layout.

Embedding rCharts

If you type:

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

with option echo = F, results = ‘asis’ you will embed the following rChart on the slides:

simplestApp

Publishing to github

  • First, log in to GitHub and create a new empty repository.
  • Use the following command, but replace user with your username and repo with the name of your new repository (both arguments are strings).
publish_github(user, repo)