How do I add polygons from Global Administrative areas, so they are clickable.
The simple way describe in the docs
that I tried is
adm <- getData('GADM', country='UKR', level=1)
leaflet() %>% addTiles() %>% addPolygons(data=adm, weight = 3, fillColor = col)
But imagine I want a leaflet map that will have onClick actions later.
Based on SuperZip, I need to have something similar to
map <- createLeafletMap(session, "map")
session$onFlushed(once=TRUE, function() {
map$addPolygon(...)
})
However, there is no addPolygon method and I am confused how will it work for SpartialPolygons
.
I also tried converting to geoJSON
, similar to https://ropensci.org/blog/2013/10/23/style-geojson-polygon/ or this SO question, but doing
polys <- fromJSON(<json data file>)
map <- createLeafletMap(session, "map")
session$onFlushed(once=TRUE, function() {
map$geoJson(polys)
})
Gives me an error
Error in func() : attempt to apply non-function
Is there a way to do it? Or what am I doing wrong?