I am trying to include a leaflet map in a xaringan presentation. There are several examples of this online, including in this presentation.
When my colleague tests the minimal example below they get an interactive map on slide 2, as expected. But when I run this I don't see the map but just see a slider box with html code.
This works on my colleague's machine:
---
title: "Testing leaflet"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
```
```{r out.width='100%', fig.height=6}
library(leaflet)
library(dplyr)
leaflet() %>% addTiles() %>% setView(lat = 30.2621, lng = -97.7382, zoom = 17)
```
Here is a screenshot of what I see on my xaringan slide:
And this is the actual html code that appears in the box on the slide:
<div id="htmlwidget-627abe20cf1eb0297594" style="width:100%;height:432px;" class="leaflet html-widget"></div>
<script type="application/json" data-for="htmlwidget-627abe20cf1eb0297594">{"x":{"options":{"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}}},"calls":[{"method":"addTiles","args":["//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",null,null,{"minZoom":0,"maxZoom":18,"tileSize":256,"subdomains":"abc","errorTileUrl":"","tms":false,"noWrap":false,"zoomOffset":0,"zoomReverse":false,"opacity":1,"zIndex":1,"detectRetina":false,"attribution":"© <a href=\"http://openstreetmap.org\">OpenStreetMap<\/a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA<\/a>"}]}],"setView":[[30.2621,-97.7382],17,[]]},"evals":[],"jsHooks":[]}</script>
Because this works on someone else's machine I assume the issue must be something to do with my set up. I've tried restarting RStudio and reinstalling xaringan, but after that I am out of ideas for what to check. Any suggestions would be greatly appreciated!
Here is my session info, in case that might help diagnose the issue:
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.3 rsconnect_0.8.16 htmltools_0.5.1.1 tools_4.0.3 xaringan_0.19 yaml_2.2.1
[7] rmarkdown_2.6 knitr_1.30 xfun_0.20 digest_0.6.27 rlang_0.4.10 evaluate_0.14