I am working from (very helpful) code provided here https://github.com/timelyportfolio/leaftime/blob/master/inst/examples/example_leaftime.R to build a timeseries map using leaflet in R. I can't seem to figure out how to define the radius of each point on my map, and hoping someone might be able to point me in the right direction.
My test data are as follows:
data <- data.frame(
"latitude" = c(36.998953, 38.998607, 40.547953, 36.475103, 34.634023),
"longitude" = c(-78.766255, -81.051412, -78.969508, -83.298121, -78.541041),
"start" = seq.Date(as.Date("2009-01-01"), by="day", length.out = 5),
"end" = seq.Date(as.Date("2009-01-01"), by = "day", length.out = 5) + 1,
"radius" = c(10, 8, 5, 12, 7)
)
I'm able to create a basic timeseries map using the code here:
library(leaflet)
library(leaftime)
library(htmltools)
library(geojsonio)
library(geojsonlint)
leaflet(geojsonio::geojson_json(data, lat="latitude", lon="longitude")) %>%
addTiles() %>%
setView(-79.771504, 36.854041, 2) %>%
addTimeline(
sliderOpts = sliderOptions(
formatOutput = htmlwidgets::JS("function(date) {return new
Date(date).toDateString()}"), position = "bottomright", duration = 3000),
timelineOpts = timelineOptions(
styleOptions = styleOptions(radius = 5, color = "black", fillColor = "blue", fillOpacity = 0.60)))
But modifying this code to customize the radius for each point doesn't work:
leaflet(geojsonio::geojson_json(data, lat="latitude", lon="longitude")) %>%
addTiles() %>%
setView(-79.771504, 36.854041, 2) %>%
addTimeline(
sliderOpts = sliderOptions(
formatOutput = htmlwidgets::JS("function(date) {return new
Date(date).toDateString()}"), position = "bottomright", duration = 3000),
timelineOpts = timelineOptions(
styleOptions = styleOptions(radius = htmlwidgets::JS("function getRadius(d) {return +d.properties.radius}"),
color = "black", fillColor = "blue", fillOpacity = 0.60)))
It seems that the error comes in when calling the java script function getRadius from the JS htmlwidget, but I'm not familiar with the java script language and not sure how to fix. Thanks for any help!