Support

Rendering PowerPoint Presentations with RStudio

Follow

To create PowerPoint presentations with RStudio:

  • Install the preview release of RStudio
  • Install the latest version of rmarkdown from CRAN

See Examples or Troubleshooting for more info. Submit PowerPoint issues at rmarkdown/issues.

Getting Started

You can render Microsoft PowerPoint presentations from R Markdown documents. This capability is made possible by recent improvements to Pandoc, which converts files from one markup format into another. To use all the features of RStudio with PowerPoint output, install the RStudio Preview which bundles Pandoc 2.x. You should also install the latest version of rmarkdown.

install.packages("rmarkdown")

Open new

The RStudio Preview now offers PowerPoint as an output format for R Markdown documents:

New File > R Markdown > Presentation > PowerPoint

Quick example

To create a PowerPoint presentation from R Markdown, specify the powerpoint_presentation output format in the YAML header.

---
title: "Untitled"
output: powerpoint_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

### R Markdown

This is an R Markdown presentation. Markdown is a simple formatting 
syntax for authoring HTML, PDF, and MS Word documents. For more 
details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that 
includes both content as well as the output of any embedded R code 
chunks within the document.

### Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

### Slide with R Output

```{r cars, echo = TRUE}
summary(cars)
```

### Slide with Plot

```{r pressure}
plot(pressure)
```

Knit to PowerPoint

When you knit an R Markdown document, RStudio renders your document in the PowerPoint output format. If you are using RStudio Desktop, your PowerPoint presentation will automatically open and take you back to the last slide you were viewing. If you are using RStudio Server, you will be prompted to download the PowerPoint presentation file.

 

You can also render files programmatically from the R console.

rmarkdown::render("in.Rmd", output_format = "powerpoint_presentation")

In some cases, you might want to make manual adjustments to your PowerPoint presentation after you render it. Fortunately, markdown elements – such as titles, text, code, and tables – are rendered natively in PowerPoint. Manually changing the slide size or design after rendering will automatically change these elements to match the new style.


Markdown Features

You can generate most elements supported by Pandoc’s Markdown with the PowerPoint output including: Inline formatting; lists; LaTeX math expressions/equations; images; hyperlinks; block quotations; and more. Here are some common elements supported in PowerPoint (for a complete list see the R Markdown Reference).

*italic* 
**bold** 
~~strikeout~~ 
~subscript~
^superscript^
[small caps]{.smallcaps} 
`verbatim`

1. Numbered list
* Unnumbered list

$math-expression$
$$math-equation$$

[link](target) 

> Block quotations

Additionally, the PowerPoint output format also supports these handy features:

Images and tables

Images will be scaled automatically to fit the slide. You can render images from file or from the web. Captions will render below the image. You can add a link to the caption or to the image itself.

# image from file
![](file)

# image from web
![](URL)

# linked image
[![](image)](link)

# plain caption
![caption](image)

# linked caption
![[caption](link)](image)

Tables render natively in PowerPoint and pick up the style defined by the reference template.

 manufacturer    displ   hwy     class
-------------    ------  -----  ---------
        audi     1.8     29      compact
   chevrolet     5.3     20        suv
       dodge     2.4     24      minivan

Table: Simple table syntax and caption.

Columns

You can use the the Two Content layout to put material in side by side columns. For example, you can put text next to an image on the same slide. To use the Two Content layout, nest two div containers of class column inside one div container of class columns.

:::::::::::::: {.columns}
::: {.column}
contents...
:::
::: {.column}
contents...
:::
::::::::::::::

Speaker notes

You can add speaker notes to slides. Speaker notes support limited formats such as bold, italics, and lists. Speaker notes, of course, will be available in handouts and in presenter view.

::: notes
This is a speaker note.

- Use basic Markdown
- like this list
- *and inline formatting*
:::

Images and tables will always be placed on new slides. The only elements that can coexist with an image or table on a slide are the slide header and caption.

Templates

The size and design of PowerPoint presentations are determined by the reference template. Pandoc ships with a default PowerPoint template that contains a blank presentation in the standard (4:3) size. If you want to change the size or design of a PowerPoint presentation, you should use a custom template. Reference a template with the reference_doc option in the YAML header.

---
title: My presentation
output: 
  powerpoint_presentation:
    reference_doc: template.pptx
---

The template should contain the following four layouts as its first four layouts. Any template included with a recent install of PowerPoint (either with .pptx or .potx extension) should work, as will most templates derived from these. Markdown headers and content will map to slide layouts and placeholders according to the rules in Structuring the Presentation.

Layouts

  1. Title. Has placeholders for a title and a subtitle. Used for information in the YAML header.
  1. Section header. Has a placeholder for a section header – content will not render on this layout. Used for headers above the slide level.
  1. Title and content. Has placeholders for title and content. Used for headers at the slide level.
  1. Two Content. Has placeholders for title and two content. Used for headers at the slide level with content in columns.

Structuring the Presentation

PowerPoint presentations have a hierarchy of title, section, and content slides whereas markdown documents have a hierarchy of headers and content. In order to structure a PowerPoint presentation, Pandoc needs to determine which markdown header level should be used for the PowerPoint slide level. For example, the markdown header ## Introduction might map to a section slide, while ### Details might map to a content slide.

By default, Pandoc sets the slide level to the highest header level in the hierarchy that is followed immediately by markdown content somewhere in the document. Once Pandoc determines the slide level, the markdown document is carved up into slides according the the following rules:

  • Headers at the slide level always starts a new slide
  • Headers above the slide level in the hierarchy create section headers
  • Headers below the slide level in the hierarchy create headers within a slide
  • A horizontal rule always starts a new slide
  • A title page is constructed automatically from the document’s title (i.e. YAML) block
---
title: Title slide (Slide 1)
output:
  powerpoint_presentation:
    slide_level: 3 # use this to override default
---

# Section header (Slide 2)

## Section header (Slide 3)

### Slide Title (Slide 4)

Slide Content (by default this content sets the slide level to three)

#### Slide content header (Slide 4)

##### Slide content header (Slide 4)

The document above creates a presentation with four slides. The default slide level is 3 because the level 3 header is the first to be followed by content. You can override the default slide level by setting the slide_level option in the YAML header. Note: If you do not want to structure your slides into sections, you can just use level 1 headers to create all your slides.


R Code Chunks

R Code Chunks can be used as a means to render R output into documents or to simply display code for illustration. Source code will render with syntax highlighting inline with other markdown text in your document. You may choose to remove source code from your PowerPoint presentation by setting echo=FALSE in the code chunk options.

Table output

By default data frames and matrices are output as they would be in the R terminal (in a monospaced font). However, if you prefer that data be displayed as a PowerPoint table you can use the knitr::kable function. Table output from kable will assume the table design of whatever template you use.

knitr::kable(mtcars)

Plot output

R code chunks can also be used to render plots. Images will be scaled automatically to fit the slide. You can change image size with fig.width and fig.height code chunk options.

plot(cars)

Webshots

You can capture HTML Widgets and Shiny apps by installing the webshot package and phantomjs. The webshot package will automatically take a screenshot of an interactive HTML Widget and insert it into your presentation. The knitr::include_app function will use webshot to embed a screenshot of a Shiny application that links viewers to a live application hosted on RStudio Connect, Shiny Server, or Shinyapps.io.

# Install
install.packages("webshot")
webshot::install_phantomjs()

# Capture an HTML Widget
dygraphs::dygraph(nhtemp, main = "New Haven Temperatures")

# Capture a Shiny app
knitr::include_app('https://gallery.shinyapps.io/goog-trend-index/')

Options

These code chunk options can be especially useful when rendering PowerPoint output.

  • echo. Control R source code in the output file. Set to FALSE if you do not want your source code included in your PowerPoint presentation.
  • cache. Save time by caching plots and other output. If document rendering becomes time consuming due to long computations or plots that are expensive to generate you can use knitr caching to improve performance.
  • screenshot.opts. Delay a webshot capture. An arbitrary URL may take a long time to load. You can increase the delay in order to give apps enough time to load before taking a webshot.
  • fig.width and fig.height. Size a plot. This should be numeric in inches. Default is 7.
  • fig.cap. Add a caption to an image. Captions will render below the image.

In this example the code chunk will wait one second for an app to load, resize the width to 15 inches, and cache the image for later use.

{r, cache=TRUE, screenshot.opts=list(delay=1), fig.width=15}

Getting Help

Click here for a list of examples. Submit PowerPoint issues to rmarkdown/issues. For more details, see these guides:

Comments