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
Are you using
mongo$find(...)
or
mongo_comunas$find(...)
?
Because the mongo command cannot be used to query your db. It is used to establish the connection to your mongodb.
You would need something along the lines of this:
mongoConnection <- mongo(collection = "test", db = "test", url = "mongodb://localhost",
verbose = FALSE, options = ssl_options())
See ?mongo for help.
Then you can call this connection for your find, aggregate, etc. queries
com <- mongoConnection$find(...)
I am guessing that the connection is what you have assigned to mongo_comunas but without seeing more of your code I don't know for sure.
Does the data you are pulling in contain any arrays? If so, you will need to use the $unwind command to un-nest these arrays.
You may also need to use "flatten" from the jsonlite package to further flatten out your data into a non-nested dataframe.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.