Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is drill-down in choropleth maps possible? #41

Closed
pssguy opened this issue Feb 8, 2015 · 6 comments
Closed

Is drill-down in choropleth maps possible? #41

pssguy opened this issue Feb 8, 2015 · 6 comments

Comments

@pssguy
Copy link

pssguy commented Feb 8, 2015

If I create a chroropleth map of the US states, using addPolygons, is it possible to have an event which would select the chosen state so that county map data / and a resultant map of that state alone can be produced?

@jcheng5
Copy link
Member

jcheng5 commented Mar 20, 2015

Yes, if the map outputId is "foo" you could look at input$foo_shape_click which will give you either NULL or a list like this:

list(
  lat = latitude,
  lng = longitude,
  id = layerId
)

@jcheng5 jcheng5 closed this as completed Mar 20, 2015
@pssguy
Copy link
Author

pssguy commented Jun 4, 2015

Thanks Joe. I can extract a lat and lon this way.

However, I want to return the country clicked on, which is, say, in the data$country field from the underlying data object. I assume I can use the data argument of addPolygons but I cannot seem to return it correctly

getMapData = function(data,location,session){
# want to return country
  })

map <-    leaflet(data = data) %>%
addTiles()

 map %>% 
addPolygons(...,
 data = getMapData(map))

Any help appreciated

@blmoore
Copy link

blmoore commented Jun 5, 2015

Use layerId (e.g. set polygon layerId's to respective county), then capture as shown above?

@pssguy
Copy link
Author

pssguy commented Jun 5, 2015

Thanks guys. layerId = data$country looks good

@jcheng5
Copy link
Member

jcheng5 commented Jun 5, 2015

Yep. You don't need to pass the data arg to addPolygons, as the
leaflet(data) argument is inherited by default. And you can do layerId = ~country instead of data$country, if you want to. Read this whole page for
more information: http://rstudio.github.io/leaflet/map_widget.html

On Fri, Jun 5, 2015 at 6:57 AM pssguy notifications@github.com wrote:

Thanks guys. layerId = data$country looks good


Reply to this email directly or view it on GitHub
#41 (comment).

@efh0888
Copy link

efh0888 commented Jun 19, 2015

Hey Joe,

This was super helpful.

I've been able to implement a drill-down leaflet map going from country to state/province with an info control that changes on hover, but it's still pretty buggy. Would you mind looking at my code at https://github.com/efh0888/leafletDrilldown for some help? The README has all the details...

Edit: you can also see a live version at https://efh0888.shinyapps.io/leafletDrilldown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants