Skip to content

Saving leaflet maps

May 21, 2018

Leaflet is a great way to create maps in R which gets a background map from the internet. In RStudio at least, the map is opened in the viewer pane and is not a plot in the usual sense (e.g. opening in a device). That means that you can’t save it via the usual method of e.g.

png("x.png")leaflet() %>% addTiles() 
dev.off()

It just produces and empty plot. fdetsch gives the answer  of how to save leaflet figures on this StackOverflow answer, which uses the mapview package.

library(leaflet)
library(mapview)
m <- leaflet() %>% addTiles()
mapshot(m, file = "world.png")

Hope that helps someone 🙂

Update ——

An answer to this StackOverflow question shows how to turn off zooming and scrolling in leaflet maps…might be useful…

Update 2 —–

An answer to this StackOverflow question shows how to use different Tiles (background maps)… reliefs for instance…

The various options are listed here.

 

 

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: