r - How to read a geojson file containing feature collections to leaflet-shiny directly -
my question how read geojson file containing feature collections leaflet-shiny. have seen joe's github https://github.com/jcheng5/leaflet-shiny/blob/master/inst/examples/geojson/server.r did not utilize external dataset created geojson manually. confused whether
is possible read geojson file leaflet-shiny directly? if not, construction of feature collections in shiny (in joe's post multi-polygon) , how create in faster , easier way?
you're looking able manipulate geojson file straight in r-shiny
, r
opposed reading static file.
as mentioned, can feed string containing geojson leaflet-shiny
such geojson featurecollection:
{ "type": "featurecollection", "features": [ { "type": "feature", "properties": {"party": "republican"}, "id": "north dakota", "geometry": { "type": "polygon", "coordinates": [[ [-104.05, 48.99], [-97.22, 48.98], [-96.58, 45.94], [-104.03, 45.94], [-104.05, 48.99] ]] } }, { "type": "feature", "properties": {"party": "democrat"}, "id": "colorado", "geometry": { "type": "polygon", "coordinates": [[ [-109.05, 41.00], [-102.06, 40.99], [-102.03, 36.99], [-109.04, 36.99], [-109.05, 41.00] ]] } } ] }
then can utilize rjsonio::fromjson
read object in format provided in illustration , manipulate in r
such (note: appears have add together styles after reading geojson file opposed reading geojson featurecollection file has styles):
geojson <- rjsonio::fromjson(filelocation) geojson[[2]][[1]]$properties$style <- list(color = "red",fillcolor = "red") geojson[[2]][[2]]$properties$style <- list(color = "blue",fillcolor = "blue") geojson$style <- list(weight = 5,stroke = "true",fill = "true",opacity = 1,fillopacity = 0.4)
this give same r
object if had entered this:
geojson <- list( type = "featurecollection", features = list( list( type = "feature", geometry = list(type = "multipolygon", coordinates = list( list( list( c(-109.05, 41.00), c(-102.06, 40.99), c(-102.03, 36.99), c(-109.04, 36.99), c(-109.05, 41.00) ) ) ) ), properties = list( party = "democrat", style = list( fillcolor = "blue", color = "blue" ) ), id = "colorado" ), list( type = "feature", geometry = list(type = "multipolygon", coordinates = list( list( list( c(-104.05, 48.99), c(-97.22, 48.98), c(-96.58, 45.94), c(-104.03, 45.94), c(-104.05, 48.99) ) ) ) ), properties = list( party = "republican", style = list( fillcolor = "red", color = "red" ) ), id = "north dakota" ) ), style = list( weight = 5, stroke = "true", fill = "true", fillopacity = 0.4 opacity = 1 ))
r leaflet shiny
No comments:
Post a Comment