i'm building shiny app, used leaflet to plot a map with markers and polygons.
At this point i have a map, with some markers and one polygon at time
This is part of my code, with this i can render a Polygon in leaflet map but only if com <- mongo$find('{"id" : "Temuco"}')
have one name (Temuco or Santiago), if i put '{"id" : {"$in":["Temuco", "Santiago"]}}'
all crashed with this error: 'options' must be a fully named list, or have no names (NULL)
com <- mongo_comunas$find('{"nombre": {"$in":["Temuco", "Santiago", "etcetcetc"]}}')
build_list <- split(com, com$id)
build_list <- lapply(build_list, function(x){x["id"]<- NULL;x})
build_list <- lapply(build_list, function(x){x["order"]<- NULL;x})
build_list <- lapply(build_list, function(x){x["hole"]<- NULL;x})
build_list <- lapply(build_list, function(x){x["piece"]<- NULL;x})
build_list <- lapply(build_list, function(x){x["group"]<- NULL;x})
ps <- lapply(build_list, Polygon)
ps <- Polygons(ps, ID = 1)
ps <- SpatialPolygons(list(ps), proj4string =CRS("+proj=longlat"))
output$mymap <- renderLeaflet({
leaflet(data = ps) %>% addTiles() %>% addPolygons())
})
with only com <- mongo$find('{"id" : "Temuco"}')
(or another id) all its good. I used ggplot with that function and render two or three or more polygons at time but with leaflet all crashed.
data stored in mongo like:
long lat order hole piece id group
1 -72.8012 -38.8337 914361 FALSE 1 Temuco Temuco.1
.
.
.
200 -72.5503 -38.7324 919738 FALSE 1 Santiago Santiago.1
I appreciate if anyone can guide me in this problem