R htmlwidgets with reveal.js

1k views Asked by At

How can I use the great htmlwidgets (for example http://rstudio.github.io/leaflet/) with reveal.js and Rmarkdown?

This mwe (not reveal.js) works:

---
title: "Maptest 1"
output: html_document
---

##  Map

```{r, echo=FALSE}
library(leaflet)
m <- leaflet()
m <- addTiles(m)
m <- addMarkers(m, lng=174.768, lat=-36.852, popup="The birthplace of R")
m
```

But this one doesn't:

---
title: "Maptest 2"
output: revealjs::revealjs_presentation
---

##  Map

```{r, echo=FALSE}
library(leaflet)
m <- leaflet()
m <- addTiles(m)
m <- addMarkers(m, lng=174.768, lat=-36.852, popup="The birthplace of R")
m
```

I re-used the example from the htmlwidgets-webpage, and the reveal.js-template is from https://github.com/jjallaire/revealjs

1

There are 1 answers

2
Steve Bronder On

To use reveal.js you need to specify the framework and extension widgets in your header. Also make sure you have the newest version of slidify and htmlwidgets.

---
title       : Titley Title Titler
subtitle    : subtitileir
author      : Author Authoria
job         : Jobby job, CJJ
framework   : revealjs        # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js  # {highlight.js, prettify, highlight}
hitheme     : github      # 
widgets     : []            # {mathjax, quiz, bootstrap}
mode        : selfcontained # {standalone, draft}
knit        : slidify::knit2slides
ext_widgets: {rCharts: "libraries/highcharts"}
revealjs:
  theme: Simple
--- 

### Title-y Title Titler


 Tu-title space title
 \- Author Authorio

---