Saving leaflet output as html

h.l.m picture h.l.m · May 7, 2015 · Viewed 25.9k times · Source

I am using RStudio to create some some leaflet images.

I would like to be able to save the output as an HTML so that it can be emailed and others can view it.

Below is some sample R code which was taken from [here] to create a sample leaflet image.

devtools::install_github('rstudio/leaflet')
library(leaflet)
rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)
m = leaflet() %>% addTiles() %>% addCircles(rand_lng(50), rand_lat(50), radius = runif(50, 10, 200))
m

Any code to be able to the output as HTML would be much appreciated...

Answer

einar picture einar · Jul 26, 2015

Something like:

library(htmlwidgets)
saveWidget(m, file="m.html")

seems to work on most widgets.