I'm trying to create a leaflet plot incorporating a time slider and heatmaps. I can get heatmaps and add timelines separately with no problems, but I can't figure out how to combine them together.
I've tried using ideas from this resource and downloaded a local version of the js file here. I'm not very familiar with javascript and admittedly have no idea what I'm doing after this point.
This is what I have so far:
library(pacman)
p_load(tidyverse,leaflet,htmltools,htmlwidgets,leaftime)
# this references my local download of the leaflet-heat.js file
heatPlugin <- htmlDependency("Leaflet.heat", "0.2.0",
src = normalizePath("."),
script = "leaflet-heat.js"
)
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
# Prep data
cohort %>% transmute(lat=lat,long=long,start=Date,end=Date+7) %>%
geojsonio::geojson_json(lat="lat",lon="long")
# Map
leaflet(cohort) %>% addTiles() %>%
registerPlugin(heatPlugin) %>%
addTimeline(timelineOpts=timelineOptions(
pointToLayer=htmlwidgets::JS("function(data, latlng) {
return L.heatLayer(latlng,{radius:15,blur:25})
}"
)))
The html renders with no problems and the map also is output with the timeline box in the corner with correct dates, but no heatmap colors appear on the map. I'd be very grateful for any kind of assitance here.
For clarity, I know what I wish to do can be fulfilled with Shiny, but at the moment my institution is not allowing us to use Shiny.