blob: b9ec1bc29cd2f4857e3795dfd6880adcab768ec7 [file] [log] [blame]
JJ Allaire5dc9fe02016-01-30 18:44:51 -05001---
2title: "R Markdown Format for reveal.js Presentations"
3output:
christophe dervieux42886a12021-09-16 11:36:01 +02004 github_document: default
JJ Allaire5dc9fe02016-01-30 18:44:51 -05005---
6
christophe dervieux42886a12021-09-16 11:36:01 +02007<!-- badges: start -->
8[![CRAN status](https://www.r-pkg.org/badges/version/revealjs)](https://CRAN.R-project.org/package=revealjs)
9[![R-CMD-check](https://github.com/rstudio/revealjs/workflows/R-CMD-check/badge.svg)](https://github.com/rstudio/revealjs/actions)
10<!-- badges: end -->
11
JJ Allaire5dc9fe02016-01-30 18:44:51 -050012## Overview
13
Atsushi Yasumotoe734cd82020-08-10 21:48:18 +090014This repository provides an [R Markdown](http://rmarkdown.rstudio.com) custom format for [reveal.js](https://revealjs.com/) HTML presentations.
JJ Allaire5dc9fe02016-01-30 18:44:51 -050015
16You can use this format in R Markdown documents by installing this package as follows:
17
18```r
JJ Allaired9f38d22016-01-31 14:15:59 -050019install.packages("revealjs", type = "source")
JJ Allaire5dc9fe02016-01-30 18:44:51 -050020```
21
22
Atsushi Yasumotoe734cd82020-08-10 21:48:18 +090023To 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 Allaire5dc9fe02016-01-30 18:44:51 -050024
25 ---
26 title: "Habits"
27 author: John Doe
28 date: March 22, 2005
29 output: revealjs::revealjs_presentation
30 ---
31
32 # In the morning
33
34 ## Getting up
35
36 - Turn off alarm
37 - Get out of bed
38
39 ## Breakfast
40
41 - Eat eggs
42 - Drink coffee
43
44 # In the evening
45
46 ## Dinner
47
48 - Eat spaghetti
49 - Drink wine
50
51 ## Going to sleep
52
53 - Get in bed
54 - Count sheep
55
Daniel Chen46087c32016-03-21 17:58:14 -040056## Rendering
57
Daniel Chen81a14342016-03-21 18:00:56 -040058Depending on your use case, there are 3 ways you can render the presentation.
Daniel Chen46087c32016-03-21 17:58:14 -040059
601. RStudio
612. R console
623. Terminal (e.g., bash)
63
64### RStudio
65
66When creating the presentation in RStudio, there will be a `Knit` button
67right below the source tabs.
68By 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.
69
Daniel Chen81a14342016-03-21 18:00:56 -040070Note: Unlike the the other slideshow outputs, the slideshow viewer popup from RStudio will be blank,
Daniel Chen46087c32016-03-21 17:58:14 -040071to view the slide show click the `open in browser` button,
72and the slide show will render in your default web browser.
73
74### R Console
75
76The `Knit` button is actually calling the `rmarkdown::render()` function.
Daniel Chen81a14342016-03-21 18:00:56 -040077So, to render the document within the R console:
Daniel Chen46087c32016-03-21 17:58:14 -040078
79```r
80rmarkdown::render('my_reveal_presentation.Rmd')
81```
82
83There are many other output tweaks you can use by directly calling `render`.
84You can read up on the [documentation](https://cran.r-project.org/web/packages/rmarkdown/rmarkdown.pdf) for more details.
85
86### Command Line
87
88When you need the presentation to be rendered from the command line:
89
90```bash
91Rscript -e "rmarkdown::render('my_reveal_presentation.Rmd')"
92```
93
JJ Allaire5dc9fe02016-01-30 18:44:51 -050094## Display Modes
95
96The following single character keyboard shortcuts enable alternate
97display modes:
98
99- `'f'` enable fullscreen mode
100
101- `'o'` enable overview mode
102
103Pressing `Esc` exits all of these modes.
104
105## Incremental Bullets
106
107You can render bullets incrementally by adding the `incremental` option:
108
109 ---
110 output:
111 revealjs::revealjs_presentation:
112 incremental: true
113 ---
114
115If you want to render bullets incrementally for some slides but not
116others you can use this syntax:
117
118 > - Eat eggs
119 > - Drink coffee
120
121## Appearance and Style
122
123There are several options that control the appearance of revealjs presentations:
124
125* `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").
126
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500127* `highlight` specifies the syntax highlighting style. Supported styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", and "haddock". Pass null to prevent syntax highlighting.
128
129* `center` specifies whether you want to vertically center content on slides (this defaults to false).
130
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500131For example:
132
133 ---
134 output:
135 revealjs::revealjs_presentation:
136 theme: sky
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500137 highlight: pygments
138 center: true
139 ---
140
JJ Allaire41921d32016-01-30 19:11:43 -0500141## Slide Transitions
142
Jon Caldera35857d2017-04-11 16:38:58 +0200143You can use the `transition` and `background_transition` options to specify the global default slide transition style:
JJ Allaire41921d32016-01-30 19:11:43 -0500144
145* `transition` specifies the visual effect when moving between slides. Available transitions are "default", "fade", "slide", "convex", "concave", "zoom" or "none".
146
147* `background_transition` specifies the background transition effect when moving between full page slides. Available transitions are "default", "fade", "slide", "convex", "concave", "zoom" or "none".
148
149For example:
150
151 ---
152 output:
153 revealjs::revealjs_presentation:
154 transition: fade
155 ---
156
157
158You can override the global transition for a specific slide by using the data-transition attribute, for example:
159
160 ## Use a zoom transition {data-transition="zoom"}
161
162 ## Use a faster speed {data-transition-speed="fast"}
163
164You can also use different in and out transitions for the same slide, for example:
165
166 ## Fade in, Slide out {data-transition="slide-in fade-out"}
167
168 ## Slide in, Fade out {data-transition="fade-in slide-out"}
169
170
JJ Allaire8382c3e2016-01-30 19:04:31 -0500171## Slide Backgrounds
172
173Slides 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.
174
175 ## CSS color background {data-background=#ff0000}
176
177 ## Full size image background {data-background="background.jpeg"}
178
179 ## Video background {data-background-video="background.mp4"}
180
181 ## Embed a web page as a background {data-background-iframe="https://example.com"}
182
183Backgrounds 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.
184
Jon Caldera35857d2017-04-11 16:38:58 +0200185## 2-D Presentations
JJ Allairede1ed652016-01-30 19:41:18 -0500186
187You 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:
188
189 # Horizontal Slide 1
190
191 ## Vertical Slide 1
192
193 ## Vertical Slide 2
194
195 # Horizontal Slide 2
196
197With 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".
198
199
200
JJ Allaire5f514242016-07-12 10:28:23 -0400201## Reveal Options
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500202
JJ Allaire064552c2017-02-10 10:28:41 -0500203Reveal.js has many additional options to configure it's behavior. You can specify any of these options using `reveal_options`, for example:
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500204
205 ---
206 title: "Habits"
207 output:
208 revealjs::revealjs_presentation:
209 self_contained: false
210 reveal_options:
211 slideNumber: true
212 previewLinks: true
213 ---
214
215You can find documentation on the various available Reveal.js options here: <https://github.com/hakimel/reveal.js#configuration>.
216
217
218## Figure Options
219
220There are a number of options that affect the output of figures within reveal.js presentations:
221
222* `fig_width` and `fig_height` can be used to control the default figure width and height (7x5 is used by default)
223
224* `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.
225
226* `fig_caption` controls whether figures are rendered with captions
227
228For example:
229
230 ---
231 title: "Habits"
232 output:
233 revealjs::revealjs_presentation:
234 fig_width: 7
235 fig_height: 6
236 fig_caption: true
237 ---
238
239
240## MathJax Equations
241
242By 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:
243
244* Specify "default" to use an https URL from the official MathJax CDN.
245
246* 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.
247
248* Specify an alternate URL to load MathJax from another location.
249
250* Specify null to exclude MathJax entirely.
251
252For example, to use a local copy of MathJax:
253
254 ---
255 title: "Habits"
256 output:
257 revealjs::revealjs_presentation:
258 mathjax: local
259 self_contained: false
260 ---
261
262To use a self-hosted copy of MathJax:
263
264 ---
265 title: "Habits"
266 output:
267 revealjs::revealjs_presentation:
268 mathjax: "http://example.com/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
269 ---
270
271To exclude MathJax entirely:
272
273 ---
274 title: "Habits"
275 output:
276 revealjs::revealjs_presentation:
277 mathjax: null
278 ---
279
280## Document Dependencies
281
Jon Caldera35857d2017-04-11 16:38:58 +0200282By 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 Allaire5dc9fe02016-01-30 18:44:51 -0500283
284 ---
285 title: "Habits"
286 output:
287 revealjs::revealjs_presentation:
288 self_contained: false
289 ---
290
291Note 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`.
292
293One 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:
294
295 ---
296 title: "Habits"
297 output:
298 revealjs::revealjs_presentation:
299 self_contained: false
300 lib_dir: libs
301 ---
302
JJ Allaire5f514242016-07-12 10:28:23 -0400303## Reveal Plugins
JJ Allaire82a8dee2016-07-12 10:25:36 -0400304
305You can enable various reveal.js plugins using the `reveal_plugins` option. Plugins currently supported include:
306
307| Plugin | Description |
308|----------------------------|---------------------------------------------|
Atsushi Yasumotoe734cd82020-08-10 21:48:18 +0900309| [notes](https://revealjs.com/speaker-view/) | Present per-slide notes in a separate browser window. |
JJ Allaire82a8dee2016-07-12 10:25:36 -0400310| [zoom](http://lab.hakim.se/zoom-js/) | Zoom in and out of selected content with Alt+Click. |
311| [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 Allaire375805c2016-11-15 08:56:43 -0500312| [chalkboard](https://github.com/rajgoel/reveal.js-plugins/tree/master/chalkboard) | Include handwritten notes within a presentation. |
JJ Allaire064552c2017-02-10 10:28:41 -0500313| [menu](https://github.com/denehyg/reveal.js-menu) | Include a navigation menu within a presentation. |
JJ Allaire82a8dee2016-07-12 10:25:36 -0400314
315Note 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:
316
317 ---
318 title: "Habits"
319 output:
320 revealjs::revealjs_presentation:
321 self_contained: false
322 reveal_plugins: ["notes", "search"]
323 ---
324
JJ Allaire064552c2017-02-10 10:28:41 -0500325You can specify additional options for the `chalkboard` and `menu` plugins using `reveal_options`, for example:
JJ Allaire375805c2016-11-15 08:56:43 -0500326
327 ---
328 title: "Habits"
329 output:
330 revealjs::revealjs_presentation:
331 self_contained: false
JJ Allaire064552c2017-02-10 10:28:41 -0500332 reveal_plugins: ["chalkboard", "menu"]
JJ Allaire375805c2016-11-15 08:56:43 -0500333 reveal_options:
334 chalkboard:
335 theme: whiteboard
336 toggleNotesButton: false
JJ Allaire064552c2017-02-10 10:28:41 -0500337 menu:
338 side: right
JJ Allaire375805c2016-11-15 08:56:43 -0500339 ---
340
341
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500342## Advanced Customization
343
344### Includes
345
346You 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:
347
348 ---
349 title: "Habits"
350 output:
351 revealjs::revealjs_presentation:
352 includes:
353 in_header: header.html
354 before_body: doc_prefix.html
355 after_body: doc_suffix.html
356 ---
357
358
359### Pandoc Arguments
360
Jon Caldera35857d2017-04-11 16:38:58 +0200361If 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 Allaire5dc9fe02016-01-30 18:44:51 -0500362
363 ---
364 title: "Habits"
365 output:
366 revealjs::revealjs_presentation:
367 pandoc_args: [
368 "--title-prefix", "Foo",
369 "--id-prefix", "Bar"
370 ]
371 ---
372
Atsushi Yasumotoe734cd82020-08-10 21:48:18 +0900373Documentation on all available pandoc arguments can be found in the [pandoc user guide](https://pandoc.org/MANUAL.html#options).
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500374
375## Shared Options
376
Jon Caldera35857d2017-04-11 16:38:58 +0200377If 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 Allaire5dc9fe02016-01-30 18:44:51 -0500378
379**\_output.yaml**
380
381```yaml
382revealjs::revealjs_presentation:
383 theme: sky
384 transition: fade
385 highlight: pygments
386```
387
388All 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.
Christophe Dervieux7f1add52021-09-15 15:42:07 +0200389
390## Code of Conduct
391
392Please note that the revealjs project is released with a [Contributor Code of Conduct](https://pkgs.rstudio.com/revealjs/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.