Closed smartinsightsfromdata closed 9 years ago
Replace alert(geography.properties.name);
with
Shiny.onInputChange(id + "_click", {
name: geography.properties.name,
'.nonce': Math.random()
});
Then if the map ID is "foo" you could use input$foo$name
to detect the property name (be sure to verify that input$foo isn't NULL
first).
@jcheng5 Thanks for the input (on issue #76 and #75).
I am very keen for this to work because it would allow very cool dashboards, where you click on a specific state (or county, or postcode) on the map and you get a table of data associated to the specific element.
Your help (and anybody's help of course) to resolve #75 would be very much appreciated!
I know @ramnathv was well down the path on a datamaps widget. Perhaps he has some code that can handle all of this and more.
Very exiting: it works! This is the function I've used:
Shiny.onInputChange(el.id, {
name: geography.properties.name,
'.nonce': Math.random()
});
I've also found this article quite useful.
Thank you so much for the help. I'll update the library on github with the change.
Yeah @timelyportfolio, @smartinsightsfromdata. I will be releasing a new version of rMaps
shortly. It is built on top of htmlwidgets
and will have datamaps
among other mapping libraries.
I'm working to a wrapper for the great library datamaps (already available with rCharts but with issues with shiny, so I thought of a brand new implementation).
At present everything seems to work. Only one important functionality is missing.
I would like to get back to the server the name of the state (or postcode, county etc.) that the user has clicked. This callback is already available with datamaps:
And my code duly displays (useless!) popups with the name of the states you click.
How to get geography.properties.name back to the R server??
(apologies but I am NO javascript programmer!)