5

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!

Dendrobates
  • 3,294
  • 6
  • 37
  • 56
  • Are you just saving the base (tile) layer, or are you trying to save everything the user sees including overlays? – nothingisnecessary Oct 28 '15 at 14:33
  • Possible duplicate of [How to get png image of a CSS styled element using canvas with transparent background?](http://stackoverflow.com/questions/14959367/how-to-get-png-image-of-a-css-styled-element-using-canvas-with-transparent-backg) – nothingisnecessary Oct 28 '15 at 14:35
  • 1
    see http://stackoverflow.com/questions/33508486/create-a-gif-from-a-series-of-leaflet-maps-in-r/33516902#33516902 – Rorschach Nov 06 '15 at 05:23
  • Thanks for your input! Your links led indeed to the solution. – Dendrobates Dec 15 '15 at 15:36

0 Answers0