I think I have a suggestion -- although it may be a bit horrid, it seemed to have worked
- I took advantage of purrr::reduce()
library(tidyverse)
library(leaflet)
m0 <- leaflet() %>%
setView(lng = -71.0589, lat = 42.3601, zoom = 12) %>%
addTiles()
df_circles <- tibble::tribble(
~lng, ~lat, ~radius, ~color, ~group,
-71.0589, 42.3601, 1000, "green", "group1",
-71.02, 42.3601, 800, "purple", "group2",
-71.0869, 42.3206, 650, "blue", "group3"
)
list_circles <- split(df_circles, 1:nrow(df_circles))
add_circle0 <- function(map, list0){
addCircles(map = map,
lng = list0$lng,
lat = list0$lat,
radius = list0$radius,
color = list0$color,
group = list0$group)
}
m1 <- reduce(list_circles, add_circle0, .init = m0)
m1 %>%
addLayersControl(
overlayGroups = c("group1", "group2","group3"),
options = layersControlOptions(collapsed = FALSE)
)