I realize that this largely defeats the purpose of using an interactive leaflet
map, but I'm writing a traditional paper book and I want to show how the leaflet
package for R works. I'm writing the book in LaTeX and rendering with knitr
. Is there a way to have a leaflet
map render as a raster image such that it could be included in this book?
Here is a minimal example:
library(leaflet)
map <- leaflet() %>%
addTiles() %>%
addMarkers(lng = -77.03673, lat = 38.89761)
Now if I try a chunk like:
<<>>=
map
@
I get this error:
Error in validateCssUnit(sizeInfo$width): "maxwidth" is not a valid CSS unit
(e.g., "100%", "400px", "auto")
Trying to save as a PNG doesn't work either:
<<>>=
png(filename = "test.png")
map
dev.off()
@
map
doesn't inherit from ggplot
, so ggsave
won't work either.
Is there any way to make this work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…