Learn R Programming

leaflet.extras2 (version 1.1.0)

addTimeslider: Add Time Slider to Leaflet

Description

The LeafletSlider plugin enables you to dynamically add and remove Markers on a map by using a JQuery UI slider.

Usage

addTimeslider(map, data, options = timesliderOptions())

Arguments

map

a map widget

data

data must be a POINT Simple Feature with a time column.

options

List of additional options. See timesliderOptions

Value

the new map object

References

https://github.com/dwilhelm89/LeafletSlider

See Also

Other Timeslider Functions: removeTimeslider(), timesliderOptions()

Examples

Run this code
# NOT RUN {
library(leaflet)
library(leaflet.extras2)
library(sf)
library(geojsonsf)

data <- sf::st_as_sf(leaflet::atlStorms2005[1,])
data <- st_cast(data, "POINT")
data$time = as.POSIXct(
  seq.POSIXt(Sys.time() - 1000, Sys.time(), length.out = nrow(data)))

leaflet() %>%
  addTiles() %>%
  addTimeslider(data = data,
             options = timesliderOptions(
               position = "topright",
               timeAttribute = "time",
               range = TRUE)) %>%
  setView(-72, 22, 4)
# }

Run the code above in your browser using DataLab