I would like to create an animated map, based on leaflet maps, using R Studio. Previously this was working with ggmaps & ggplot using saveHTML, but the function saveHTML is unable to make images of the leaflet maps and hence not able to make a html page showing an animated map.
Any suggestions how to save leaflet maps as images, or how to use saveHTML to get an animated map?
Data looks like:
long = c(-73.95,-74,-74.05)
lat = c(40.8, 40.7, 40.4)
minute = c(15, 0, 18)
tripData <- data.frame(long,lat,minute)
Code so far:
library(animation)
library(leaflet)
plotLeaflet <- function(.minute){
df = subset(tripData, minute == .minute);
(m2 <- m %>% addCircles(data = df));
print(m2);
}
# Create animation
range_m = 0:59
oopt <- animation::ani.options(interval = 0.1)
FUN3 <- function() {
mapply(function(x) {
plotLeaflet(x);
animation::ani.pause()
},range_m)
}
saveHTML(FUN3(), autoplay = FALSE, loop = FALSE, verbose = FALSE, outdir = "images/animate/new",
single.opts = "'controls': ['first', 'previous', 'play', 'next', 'last', 'loop', 'speed'], 'delayMin': 0")
Help will be highly appreciated!