JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 1 | --- |
| 2 | title: "R Markdown Format for reveal.js Presentations" |
| 3 | output: |
| 4 | github_document: |
| 5 | toc: true |
JJ Allaire | b987356 | 2016-01-30 19:26:11 -0500 | [diff] [blame] | 6 | toc_depth: 2 |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 7 | --- |
| 8 | |
| 9 | ## Overview |
| 10 | |
Atsushi Yasumoto | e734cd8 | 2020-08-10 21:48:18 +0900 | [diff] [blame] | 11 | This repository provides an [R Markdown](http://rmarkdown.rstudio.com) custom format for [reveal.js](https://revealjs.com/) HTML presentations. |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 12 | |
| 13 | You can use this format in R Markdown documents by installing this package as follows: |
| 14 | |
| 15 | ```r |
JJ Allaire | d9f38d2 | 2016-01-31 14:15:59 -0500 | [diff] [blame] | 16 | install.packages("revealjs", type = "source") |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 17 | ``` |
| 18 | |
| 19 | |
Atsushi Yasumoto | e734cd8 | 2020-08-10 21:48:18 +0900 | [diff] [blame] | 20 | To create a [reveal.js](https://revealjs.com/) presentation from R Markdown you specify the `revealjs_presentation` output format in the front-matter of your document. You can create a slide show broken up into sections by using the `#` and `##` heading tags (you can also create a new slide without a header using a horizontal rule (`----`). For example here's a simple slide show: |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 21 | |
| 22 | --- |
| 23 | title: "Habits" |
| 24 | author: John Doe |
| 25 | date: March 22, 2005 |
| 26 | output: revealjs::revealjs_presentation |
| 27 | --- |
| 28 | |
| 29 | # In the morning |
| 30 | |
| 31 | ## Getting up |
| 32 | |
| 33 | - Turn off alarm |
| 34 | - Get out of bed |
| 35 | |
| 36 | ## Breakfast |
| 37 | |
| 38 | - Eat eggs |
| 39 | - Drink coffee |
| 40 | |
| 41 | # In the evening |
| 42 | |
| 43 | ## Dinner |
| 44 | |
| 45 | - Eat spaghetti |
| 46 | - Drink wine |
| 47 | |
| 48 | ## Going to sleep |
| 49 | |
| 50 | - Get in bed |
| 51 | - Count sheep |
| 52 | |
Daniel Chen | 46087c3 | 2016-03-21 17:58:14 -0400 | [diff] [blame] | 53 | ## Rendering |
| 54 | |
Daniel Chen | 81a1434 | 2016-03-21 18:00:56 -0400 | [diff] [blame] | 55 | Depending on your use case, there are 3 ways you can render the presentation. |
Daniel Chen | 46087c3 | 2016-03-21 17:58:14 -0400 | [diff] [blame] | 56 | |
| 57 | 1. RStudio |
| 58 | 2. R console |
| 59 | 3. Terminal (e.g., bash) |
| 60 | |
| 61 | ### RStudio |
| 62 | |
| 63 | When creating the presentation in RStudio, there will be a `Knit` button |
| 64 | right below the source tabs. |
| 65 | By default, it will render the current document and place the rendered `HTML` file in the same directory as the source file, with the same name. |
| 66 | |
Daniel Chen | 81a1434 | 2016-03-21 18:00:56 -0400 | [diff] [blame] | 67 | Note: Unlike the the other slideshow outputs, the slideshow viewer popup from RStudio will be blank, |
Daniel Chen | 46087c3 | 2016-03-21 17:58:14 -0400 | [diff] [blame] | 68 | to view the slide show click the `open in browser` button, |
| 69 | and the slide show will render in your default web browser. |
| 70 | |
| 71 | ### R Console |
| 72 | |
| 73 | The `Knit` button is actually calling the `rmarkdown::render()` function. |
Daniel Chen | 81a1434 | 2016-03-21 18:00:56 -0400 | [diff] [blame] | 74 | So, to render the document within the R console: |
Daniel Chen | 46087c3 | 2016-03-21 17:58:14 -0400 | [diff] [blame] | 75 | |
| 76 | ```r |
| 77 | rmarkdown::render('my_reveal_presentation.Rmd') |
| 78 | ``` |
| 79 | |
| 80 | There are many other output tweaks you can use by directly calling `render`. |
| 81 | You can read up on the [documentation](https://cran.r-project.org/web/packages/rmarkdown/rmarkdown.pdf) for more details. |
| 82 | |
| 83 | ### Command Line |
| 84 | |
| 85 | When you need the presentation to be rendered from the command line: |
| 86 | |
| 87 | ```bash |
| 88 | Rscript -e "rmarkdown::render('my_reveal_presentation.Rmd')" |
| 89 | ``` |
| 90 | |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 91 | ## Display Modes |
| 92 | |
| 93 | The following single character keyboard shortcuts enable alternate |
| 94 | display modes: |
| 95 | |
| 96 | - `'f'` enable fullscreen mode |
| 97 | |
| 98 | - `'o'` enable overview mode |
| 99 | |
| 100 | Pressing `Esc` exits all of these modes. |
| 101 | |
| 102 | ## Incremental Bullets |
| 103 | |
| 104 | You can render bullets incrementally by adding the `incremental` option: |
| 105 | |
| 106 | --- |
| 107 | output: |
| 108 | revealjs::revealjs_presentation: |
| 109 | incremental: true |
| 110 | --- |
| 111 | |
| 112 | If you want to render bullets incrementally for some slides but not |
| 113 | others you can use this syntax: |
| 114 | |
| 115 | > - Eat eggs |
| 116 | > - Drink coffee |
| 117 | |
| 118 | ## Appearance and Style |
| 119 | |
| 120 | There are several options that control the appearance of revealjs presentations: |
| 121 | |
| 122 | * `theme` specifies the theme to use for the presentation (available themes are "default", "simple", "sky", "beige", "serif", "solarized", "blood", "moon", "night", "black", "league" or "white"). |
| 123 | |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 124 | * `highlight` specifies the syntax highlighting style. Supported styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", and "haddock". Pass null to prevent syntax highlighting. |
| 125 | |
| 126 | * `center` specifies whether you want to vertically center content on slides (this defaults to false). |
| 127 | |
| 128 | * `smart` indicates whether to produce typographically correct output, converting straight quotes to curly quotes, `---` to em-dashes, `--` to en-dashes, and `...` to ellipses. Note that `smart` is enabled by default. |
| 129 | |
| 130 | For example: |
| 131 | |
| 132 | --- |
| 133 | output: |
| 134 | revealjs::revealjs_presentation: |
| 135 | theme: sky |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 136 | highlight: pygments |
| 137 | center: true |
| 138 | --- |
| 139 | |
JJ Allaire | 41921d3 | 2016-01-30 19:11:43 -0500 | [diff] [blame] | 140 | ## Slide Transitions |
| 141 | |
Jon Calder | a35857d | 2017-04-11 16:38:58 +0200 | [diff] [blame] | 142 | You can use the `transition` and `background_transition` options to specify the global default slide transition style: |
JJ Allaire | 41921d3 | 2016-01-30 19:11:43 -0500 | [diff] [blame] | 143 | |
| 144 | * `transition` specifies the visual effect when moving between slides. Available transitions are "default", "fade", "slide", "convex", "concave", "zoom" or "none". |
| 145 | |
| 146 | * `background_transition` specifies the background transition effect when moving between full page slides. Available transitions are "default", "fade", "slide", "convex", "concave", "zoom" or "none". |
| 147 | |
| 148 | For example: |
| 149 | |
| 150 | --- |
| 151 | output: |
| 152 | revealjs::revealjs_presentation: |
| 153 | transition: fade |
| 154 | --- |
| 155 | |
| 156 | |
| 157 | You can override the global transition for a specific slide by using the data-transition attribute, for example: |
| 158 | |
| 159 | ## Use a zoom transition {data-transition="zoom"} |
| 160 | |
| 161 | ## Use a faster speed {data-transition-speed="fast"} |
| 162 | |
| 163 | You can also use different in and out transitions for the same slide, for example: |
| 164 | |
| 165 | ## Fade in, Slide out {data-transition="slide-in fade-out"} |
| 166 | |
| 167 | ## Slide in, Fade out {data-transition="fade-in slide-out"} |
| 168 | |
| 169 | |
JJ Allaire | 8382c3e | 2016-01-30 19:04:31 -0500 | [diff] [blame] | 170 | ## Slide Backgrounds |
| 171 | |
| 172 | Slides are contained within a limited portion of the screen by default to allow them to fit any display and scale uniformly. You can apply full page backgrounds outside of the slide area by adding a data-background attribute to your slide header element. Four different types of backgrounds are supported: color, image, video and iframe. Below are a few examples. |
| 173 | |
| 174 | ## CSS color background {data-background=#ff0000} |
| 175 | |
| 176 | ## Full size image background {data-background="background.jpeg"} |
| 177 | |
| 178 | ## Video background {data-background-video="background.mp4"} |
| 179 | |
| 180 | ## Embed a web page as a background {data-background-iframe="https://example.com"} |
| 181 | |
| 182 | Backgrounds transition using a fade animation by default. This can be changed to a linear sliding transition by specifying the `background-transition: slide`. Alternatively you can set data-background-transition on any slide with a background to override that specific transition. |
| 183 | |
Jon Calder | a35857d | 2017-04-11 16:38:58 +0200 | [diff] [blame] | 184 | ## 2-D Presentations |
JJ Allaire | de1ed65 | 2016-01-30 19:41:18 -0500 | [diff] [blame] | 185 | |
| 186 | You can use the `slide_level` option to specify which level of heading will be used to denote individual slides. If `slide_level` is 2 (the default), a two-dimensional layout will be produced, with level 1 headers building horizontally and level 2 headers building vertically. For example: |
| 187 | |
| 188 | # Horizontal Slide 1 |
| 189 | |
| 190 | ## Vertical Slide 1 |
| 191 | |
| 192 | ## Vertical Slide 2 |
| 193 | |
| 194 | # Horizontal Slide 2 |
| 195 | |
| 196 | With this layout horizontal navigation will proceed directly from "Horizontal Slide 1" to "Horizontal Slide 2", with vertical navigation to "Vertical Slide 1", etc. presented as an option on "Horizontal Slide 1". |
| 197 | |
| 198 | |
| 199 | |
JJ Allaire | 5f51424 | 2016-07-12 10:28:23 -0400 | [diff] [blame] | 200 | ## Reveal Options |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 201 | |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 202 | Reveal.js has many additional options to configure it's behavior. You can specify any of these options using `reveal_options`, for example: |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 203 | |
| 204 | --- |
| 205 | title: "Habits" |
| 206 | output: |
| 207 | revealjs::revealjs_presentation: |
| 208 | self_contained: false |
| 209 | reveal_options: |
| 210 | slideNumber: true |
| 211 | previewLinks: true |
| 212 | --- |
| 213 | |
| 214 | You can find documentation on the various available Reveal.js options here: <https://github.com/hakimel/reveal.js#configuration>. |
| 215 | |
| 216 | |
| 217 | ## Figure Options |
| 218 | |
| 219 | There are a number of options that affect the output of figures within reveal.js presentations: |
| 220 | |
| 221 | * `fig_width` and `fig_height` can be used to control the default figure width and height (7x5 is used by default) |
| 222 | |
| 223 | * `fig_retina` Specifies the scaling to perform for retina displays (defaults to 2, which currently works for all widely used retina displays). Note that this only takes effect if you are using knitr >= 1.5.21. Set to `null` to prevent retina scaling. |
| 224 | |
| 225 | * `fig_caption` controls whether figures are rendered with captions |
| 226 | |
| 227 | For example: |
| 228 | |
| 229 | --- |
| 230 | title: "Habits" |
| 231 | output: |
| 232 | revealjs::revealjs_presentation: |
| 233 | fig_width: 7 |
| 234 | fig_height: 6 |
| 235 | fig_caption: true |
| 236 | --- |
| 237 | |
| 238 | |
| 239 | ## MathJax Equations |
| 240 | |
| 241 | By default [MathJax](http://www.mathjax.org/) scripts are included in reveal.js presentations for rendering LaTeX and MathML equations. You can use the `mathjax` option to control how MathJax is included: |
| 242 | |
| 243 | * Specify "default" to use an https URL from the official MathJax CDN. |
| 244 | |
| 245 | * Specify "local" to use a local version of MathJax (which is copied into the output directory). Note that when using "local" you also need to set the `self_contained` option to false. |
| 246 | |
| 247 | * Specify an alternate URL to load MathJax from another location. |
| 248 | |
| 249 | * Specify null to exclude MathJax entirely. |
| 250 | |
| 251 | For example, to use a local copy of MathJax: |
| 252 | |
| 253 | --- |
| 254 | title: "Habits" |
| 255 | output: |
| 256 | revealjs::revealjs_presentation: |
| 257 | mathjax: local |
| 258 | self_contained: false |
| 259 | --- |
| 260 | |
| 261 | To use a self-hosted copy of MathJax: |
| 262 | |
| 263 | --- |
| 264 | title: "Habits" |
| 265 | output: |
| 266 | revealjs::revealjs_presentation: |
| 267 | mathjax: "http://example.com/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML" |
| 268 | --- |
| 269 | |
| 270 | To exclude MathJax entirely: |
| 271 | |
| 272 | --- |
| 273 | title: "Habits" |
| 274 | output: |
| 275 | revealjs::revealjs_presentation: |
| 276 | mathjax: null |
| 277 | --- |
| 278 | |
| 279 | ## Document Dependencies |
| 280 | |
Jon Calder | a35857d | 2017-04-11 16:38:58 +0200 | [diff] [blame] | 281 | By default R Markdown produces standalone HTML files with no external dependencies, using data: URIs to incorporate the contents of linked scripts, stylesheets, images, and videos. This means you can share or publish the file just like you share Office documents or PDFs. If you'd rather keep dependencies in external files you can specify `self_contained: false`. For example: |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 282 | |
| 283 | --- |
| 284 | title: "Habits" |
| 285 | output: |
| 286 | revealjs::revealjs_presentation: |
| 287 | self_contained: false |
| 288 | --- |
| 289 | |
| 290 | Note that even for self contained documents MathJax is still loaded externally (this is necessary because of it's size). If you want to serve MathJax locally then you should specify `mathjax: local` and `self_contained: false`. |
| 291 | |
| 292 | One common reason keep dependencies external is for serving R Markdown documents from a website (external dependencies can be cached separately by browsers leading to faster page load times). In the case of serving multiple R Markdown documents you may also want to consolidate dependent library files (e.g. Bootstrap, MathJax, etc.) into a single directory shared by multiple documents. You can use the `lib_dir` option to do this, for example: |
| 293 | |
| 294 | --- |
| 295 | title: "Habits" |
| 296 | output: |
| 297 | revealjs::revealjs_presentation: |
| 298 | self_contained: false |
| 299 | lib_dir: libs |
| 300 | --- |
| 301 | |
JJ Allaire | 5f51424 | 2016-07-12 10:28:23 -0400 | [diff] [blame] | 302 | ## Reveal Plugins |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 303 | |
| 304 | You can enable various reveal.js plugins using the `reveal_plugins` option. Plugins currently supported include: |
| 305 | |
| 306 | | Plugin | Description | |
| 307 | |----------------------------|---------------------------------------------| |
Atsushi Yasumoto | e734cd8 | 2020-08-10 21:48:18 +0900 | [diff] [blame] | 308 | | [notes](https://revealjs.com/speaker-view/) | Present per-slide notes in a separate browser window. | |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 309 | | [zoom](http://lab.hakim.se/zoom-js/) | Zoom in and out of selected content with Alt+Click. | |
| 310 | | [search](https://github.com/hakimel/reveal.js/blob/master/plugin/search/search.js) | Find a text string anywhere in the slides and show the next occurrence to the user. | |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 311 | | [chalkboard](https://github.com/rajgoel/reveal.js-plugins/tree/master/chalkboard) | Include handwritten notes within a presentation. | |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 312 | | [menu](https://github.com/denehyg/reveal.js-menu) | Include a navigation menu within a presentation. | |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 313 | |
| 314 | Note that the use of plugins requires that the `self_contained` option be set to false. For example, this presentation includes both the "notes" and "search" plugins: |
| 315 | |
| 316 | --- |
| 317 | title: "Habits" |
| 318 | output: |
| 319 | revealjs::revealjs_presentation: |
| 320 | self_contained: false |
| 321 | reveal_plugins: ["notes", "search"] |
| 322 | --- |
| 323 | |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 324 | You can specify additional options for the `chalkboard` and `menu` plugins using `reveal_options`, for example: |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 325 | |
| 326 | --- |
| 327 | title: "Habits" |
| 328 | output: |
| 329 | revealjs::revealjs_presentation: |
| 330 | self_contained: false |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 331 | reveal_plugins: ["chalkboard", "menu"] |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 332 | reveal_options: |
| 333 | chalkboard: |
| 334 | theme: whiteboard |
| 335 | toggleNotesButton: false |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 336 | menu: |
| 337 | side: right |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 338 | --- |
| 339 | |
| 340 | |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 341 | ## Advanced Customization |
| 342 | |
| 343 | ### Includes |
| 344 | |
| 345 | You can do more advanced customization of output by including additional HTML content or by replacing the core pandoc template entirely. To include content in the document header or before/after the document body you use the `includes` option as follows: |
| 346 | |
| 347 | --- |
| 348 | title: "Habits" |
| 349 | output: |
| 350 | revealjs::revealjs_presentation: |
| 351 | includes: |
| 352 | in_header: header.html |
| 353 | before_body: doc_prefix.html |
| 354 | after_body: doc_suffix.html |
| 355 | --- |
| 356 | |
| 357 | |
| 358 | ### Pandoc Arguments |
| 359 | |
Jon Calder | a35857d | 2017-04-11 16:38:58 +0200 | [diff] [blame] | 360 | If there are pandoc features you want to use that lack equivalents in the YAML options described above you can still use them by passing custom `pandoc_args`. For example: |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 361 | |
| 362 | --- |
| 363 | title: "Habits" |
| 364 | output: |
| 365 | revealjs::revealjs_presentation: |
| 366 | pandoc_args: [ |
| 367 | "--title-prefix", "Foo", |
| 368 | "--id-prefix", "Bar" |
| 369 | ] |
| 370 | --- |
| 371 | |
Atsushi Yasumoto | e734cd8 | 2020-08-10 21:48:18 +0900 | [diff] [blame] | 372 | Documentation on all available pandoc arguments can be found in the [pandoc user guide](https://pandoc.org/MANUAL.html#options). |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 373 | |
| 374 | ## Shared Options |
| 375 | |
Jon Calder | a35857d | 2017-04-11 16:38:58 +0200 | [diff] [blame] | 376 | If you want to specify a set of default options to be shared by multiple documents within a directory you can include a file named `_output.yaml` within the directory. Note that no YAML delimiters or enclosing output object are used in this file. For example: |
JJ Allaire | 5dc9fe0 | 2016-01-30 18:44:51 -0500 | [diff] [blame] | 377 | |
| 378 | **\_output.yaml** |
| 379 | |
| 380 | ```yaml |
| 381 | revealjs::revealjs_presentation: |
| 382 | theme: sky |
| 383 | transition: fade |
| 384 | highlight: pygments |
| 385 | ``` |
| 386 | |
| 387 | All documents located in the same directory as `_output.yaml` will inherit it's options. Options defined explicitly within documents will override those specified in the shared options file. |