In R, I would like to create a popup when hovering over a polyline that has been added to a leaflet map.
Below is some code to create three random polylines on a map.
library(leaflet)
library(dplyr)
m = leaflet() %>% addTiles()
rand_lng = function(n = 10) {rnorm(n, -93.65, .01)}
rand_lat = function(n = 10) {rnorm(n, 42.0285, .01)}
m %>% addPolylines(
c(rand_lng(10), NA, rand_lng(10), NA, rand_lng(10)),
c(rand_lat(10), NA, rand_lat(10), NA, rand_lat(10)),
color = c('red', 'green', 'blue'),
fill=FALSE, weight=2
)
I would like a different popup to occur when hovering over each of the lines.
The options
argument looks useful, especially combined with popupOptions()
but I don't see much on the hover options, and do not quite not how to integrate it.
Any help would be much appreciated.