Overview

To create a Slidy presentation from R Markdown you specify the slidy_presentation output format in the front-matter of your document. You can create a slide show broken up into sections by using the ## heading tag (you can also create a new slide without a header using a horizontal rule (----). For example here’s a simple slide show:

---
title: "Habits"
author: John Doe
date: March 22, 2005
output: slidy_presentation
---

# In the morning

## Getting up

- Turn off alarm
- Get out of bed

## Breakfast

- Eat eggs
- Drink coffee

# In the evening

## Dinner

- Eat spaghetti
- Drink wine

----

![picture of spaghetti](images/spaghetti.jpg)

## Going to sleep

- Get in bed
- Count sheep

Display Modes

The following single character keyboard shortcuts enable alternate display modes:

  • 'C' Show table of contents
  • 'F' Toggles the display of the footer
  • 'A' Toggles display of current vs all slides (useful for printing handouts)
  • 'S' Make fonts smaller
  • 'B' Make fonts larger

Incremental Bullets

You can render bullets incrementally by adding the incremental option:

---
output:
  slidy_presentation:
    incremental: true
---

If you want to render bullets incrementally for some slides but not others you can use this syntax:

> - Eat eggs
> - Drink coffee

Appearance and Style

There are several options that control the appearance of Slidy presentations:

  • highlight specifies the syntax highlighting style. Supported styles include “default”, “tango”, “pygments”, “kate”, “monochrome”, “espresso”, “zenburn”, and “haddock”. Pass null to prevent syntax highlighting.

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

For example:

---
output:
  slidy_presentation:
    highlight: pygments
---

Text Size

You can use the font_adjustment option to increase or decrease the default font size (e.g. -1 or +1) for the entire presentation. For example:

---
output:
  slidy_presentation:
    font_adjustment: -1
---

If you want to decrease the text size on an individual slide you can use the .smaller slide attribute. For example:

## Getting up {.smaller}

If you want to increase the text size on an indvidual slide you can use the .bigger slide attribute. For example:

## Getting up {.bigger}

You can also manually adjust the font size during the presentation using the ‘S’ (smaller) and ‘B’ (bigger) keys.

Custom CSS

You can add your own CSS to a Slidy presentation using the css option:

---
output:
  slidy_presentation:
    css: styles.css
---

You can also target specific slides or classes of slice with custom CSS by adding ids or classes to the slides headers within your document. For example the following slide header:

## Next Steps {#nextsteps .emphasized}

Would enable you to apply CSS to all of it’s content using either of the following CSS selectors:

#nextsteps {
   color: blue;
}

.emphasized {
   font-size: 1.2em;
}

Printing and PDF Output

You can print a Slidy presentation from within browsers that have good support for print CSS (i.e. as of this writing Google Chrome has the best support). Printing maintains most of the visual styles of the HTML version of the presentation.

To create a PDF version of a presentation you can use Print to PDF from Google Chrome.

Figure Options

There are a number of options that affect the output of figures within Slidy presentations:

  • fig_width and fig_height can be used to control the default figure width and height (7x5 is used by default)

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

  • fig_caption controls whether figures are rendered with captions

  • dev controls the graphics device used to render figures (defaults to png)

For example:

---
title: "Habits"
output:
  slidy_presentation:
    fig_width: 7
    fig_height: 6
    fig_caption: true
---

Data Frame Printing

You can enhance the default display of data frames via the df_print option. Valid values include:

Option Description
default Call the print.data.frame generic method
kable Use the knitr::kable function.
tibble Use the tibble::print.tbl_df function.
paged Create a pageable HTML table

For example:

---
title: "Habits"
output:
  html_document:
    df_print: paged
---

MathJax Equations

By default MathJax scripts are included in Slidy presentations for rendering LaTeX and MathML equations. You can use the mathjax option to control how MathJax is included:

  • Specify “default” to use an https URL from the official MathJax CDN.

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

  • Specify an alternate URL to load MathJax from another location.

  • Specify null to exclude MathJax entirely.

For example, to use a local copy of MathJax:

---
title: "Habits"
output:
  slidy_presentation:
    mathjax: local
    self_contained: false
---

To use a self-hosted copy of MathJax:

---
title: "Habits"
output:
  slidy_presentation:
    mathjax: "http://example.com/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
---

To exclude MathJax entirely:

---
title: "Habits"
output:
  slidy_presentation:
    mathjax: null
---

Document Dependencies

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 have keep depenencies in external files you can specify self_contained: false. For example:

---
title: "Habits"
output:
  slidy_presentation:
    self_contained: false
---

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.

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:

---
title: "Habits"
output:
  slidy_presentation:
    self_contained: false
    lib_dir: libs
---

Advanced Customization

Keeping Markdown

When knitr processes an R Markdown input file it creates a markdown (md) file which is subsequently tranformed into HTML by pandoc. If you want to keep a copy of the markdown file after rendering you can do so using the keep_md option:

---
title: "Habits"
output:
  slidy_presentation:
    keep_md: true
---

Includes

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:

---
title: "Habits"
output:
  slidy_presentation:
    includes:
      in_header: header.html
      before_body: doc_prefix.html
      after_body: doc_suffix.html
---

Custom Templates

You can also replace the underlying pandoc template using the template option:

---
title: "Habits"
output:
  slidy_presentation:
    template: quarterly_report.html
---

Consult the documentation on pandoc templates for additional details on templates. You can also study the default HTML template as an example.

Markdown Extensions

By default R Markdown is defined as all pandoc markdown extensions with the following tweaks for backward compatibility with the markdown package:

+autolink_bare_uris
+ascii_identifier
+tex_math_single_backslash

You can enable or disable markdown extensions using the md_extensions option (you preface an option with - to disable and + to enable it). For example:

---
title: "Habits"
output:
  html_document:
    md_extensions: -autolink_bare_uris+hard_line_breaks
---

The above would disable the autolink_bare_uris extension and enable the hard_line_breaks extension.

For more on available markdown extensions see the pandoc markdown specification.

Pandoc Arguments

If there are pandoc features you want to use that lack equivilants in the YAML options described above you can still use them by passing custom pandoc_args. For example:

---
title: "Habits"
output:
  slidy_presentation:
    pandoc_args: [
      "--title-prefix", "Foo",
      "--id-prefix", "Bar"
    ]
---

Documentation on all available pandoc arguments can be found in the pandoc user guide.

Shared Options

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 delimeters or enclosing output object are used in this file. For example:

_output.yaml

slidy_presentation:
  incremental: true
  highlight: pygments

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.