Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to include Leaflet (for R)-output into RMarkdown presentation?

According to the documentation, Leaflet output created with the "leaflet" package for R can be included into RMarkdown.

This works when the RMarkdown output is html:

---
title: "Rmarkdown HTML including Leaflet"
output: html_document
---

Show "Leaflet for R" within html: works.

```{r}
library(leaflet)
leaflet() %>%
  addTiles %>% # Add default OpenStreetMap map tiles
  setView(lng = 5.0, lat = 51.0, zoom = 6)
```

But fails when the RMarkdown output is a presentation:

---
title: "Rmarkdown Presentation including Leaflet"
output: 
  revealjs::revealjs_presentation
---

Show "Leaflet for R" within Rmarkdown presentation: fails.

```{r}
library(leaflet)
leaflet() %>%
  addTiles %>% # Add default OpenStreetMap map tiles
  setView(lng = 5.0, lat = 51.0, zoom = 6)
```

My objective is to create a presentation that includes the Leaflet output. How to accomplish this?

like image 328
Uden VH Avatar asked Mar 09 '16 14:03

Uden VH


1 Answers

Not a real solution, but a workaround: when changing from a revealjs presentation type to ioslides, the Leaflet output is shown in the presentation. The layout and interactivity do not work flawless though.

---
title: "Rmarkdown Presentation including Leaflet"
author: "UVH"
date: "March 14, 2016"
output: 
  ioslides_presentation
---

Show "Leaflet for R" within Rmarkdown "ioslides" presentation: works, but not flawless.

```{r echo=FALSE}
library(leaflet)
leaflet() %>%
  addTiles %>% # Add default OpenStreetMap map tiles
  setView(lng = 5.0, lat = 51.0, zoom = 6)
```

As I prefer using revealjs over ioslides, I hope someone can provide a better solution that does work with revealjs.

like image 163
Uden VH Avatar answered Oct 30 '22 15:10

Uden VH