leaflet map won't appear in Rmarkdown pdf file

Hello,

I am having issues viewing a map produced via the leaflet package in Rmarkdown. Here is a preview of the code I am using to display the map:

## install.packages("leaflet")
## webshot::install_phantomjs()
library(leaflet)
leaflet() %>% addTiles() %>%
  setView(lat = 32.987607, lng = -96.751466, zoom = 17) %>%
  addMarkers(lat = 32.987607, lng = -96.751466, popup = "We are here")

When I run this I am able to see my code in the pdf file produced, but the image will not appear. What's somewhat confusing is that if I use a mac the code above produces the map in the markdown file. However, if I use a windows machine only the code itself will be printed without the map.
Can somebody please explain what I must do to remedy this issue on a windows machine?

I believe this is by design- leaflet is an HTML widget (https://www.htmlwidgets.org/index.html), designed to be used with HTML outputs from R Markdown source files. This might be helpful for exporting your map into a static file you can embed in a PDF:
https://stackoverflow.com/questions/31336898/how-to-save-leaflet-in-r-map-as-png-or-jpg-file

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.