Open pssguy opened 10 years ago
Here is how you can make it work from Shiny
x = as.formula(paste(input$race, "~ abb"))
ichoropleth(x, data = race)
To enable a legend, you need to pass legend = TRUE
to the ichoropleth
function.
Datamaps
documentation will include more details and examples.
Thanks. That as.formula
function comes in handy
I have some complex column names which cause error e.g. African American.
Error in parse(text = x) : <text>:1:9: unexpected symbol
1: African American
I am sure I can hack around it, but is there a simple solution. I tried adding [] via the paste but that did not work
using
ichoropleth(x, data = race, legend = TRUE)
the legend still does not appear
Column names with spaces are not recommended. Even if you are able to resolve it correctly in R, it will trip up javascript. So my recommendation would be to replaces spaces with underscores and then use it.
Can you try this example and tell me if the legend shows up? ichoropleth
assumes that Crime
is a numerical variable, that is then discretized based on quantiles, which can be controlled using the argument ncuts
.
ichoropleth(Crime ~ State, data = subset(violent_crime, Year == 2010))
The underscore suggestion does solve the problem. Thanks
In shiny ichoropleth(Crime ~ State, data = subset(violent_crime, Year == 2010), legend=TRUE, ncuts=7) ncuts works. No legend (with or without stipulating)
I think I know the issue with stuff in Shiny. The legend option was introduced in v1 of datamaps, which is present in rMaps
. When you are using this in Shiny, it is actually using the library files from rCharts
, which contains an older version of datamaps
. I will be removing datamaps
and leaflet
from rCharts
and figure out a way to prevent conflicts in the future.
Good I thought it might be something to do with an rCharts conflict but needed that for the chartOutput function
I am trying to figure out how to put an rmap in a shiny app, but I haven't found any documentation. Could you provide an example (w/ server and ui) of how to include the "Leaflet Heatmap" from (http://rmaps.github.io/blog/posts/leaflet-heat-maps/index.html) in Shiny?
Maybe there's a corollary to renderChart from rCharts?
Thanks in advance.
rMaps
will NOT work with shiny
currently due to the fact that there is duplication in libraries with rCharts
, and by default renderChart
and chartOutput
will pick up the counterparts from rCharts
. I am working on trying to figure out the best way to remove leaflet
and datamaps
from rCharts
and also modify some code in rCharts
so that rMaps
libraries can take advantage of the same mechanisms.
Got it! Thanks for explaining
May I ask if rMaps is still incompatible with Shiny?
Unfortunately yes. The fix is actually simple in theory. But it is taking time, since it involves some fundamental changes to how things work in rCharts
, the parent package, and I want to ensure that existing charts don't break.
No worries. I have cruised through the other issues, and it seems a lot of people are interested in animated choropleths (with one or more sliders for time or whatever variable), and rMaps + Shiny seems like a promising option to do this.
Actually, the animated choropleths I show here don't require any shiny. The blog post discusses details, but I have wrapped everything into an ichoropleth
function that will write the necessary javascript for you to create the animation.
Yes, I have toyed with that, and it's fantastic already. What I'm trying to do is to hack multiple, interconnected sliders into the code, to control the choropleths through more than one value. I have failed to do this with Leaflet plugins, so trying something else :)
That should be easy to do with some minor tweaks to my ichoropleth
code. If you can provide me with a minimal reproducible example (say two sliders), I can try and post a demo of how you can tweak it with rMaps.
Here's my toy code, which is just the previous Fiddle with some standard output from ichoropleth
plus custom coordinates.
I'm a Javascript newbie, so I'm reading about ng-bind
and ng-model
right now to understand how to bind the slider values and the map properly.
Hi Ramnathv, Any news on the integration of rmaps with Shiny? I am particularly interested in fixing the problem with the legend for this application: https://github.com/Arevaju/shiny-maps. Any ideas on how this could be addressed using Shiny? Thanks for your help!
I will be releasing a new version of a datamaps
binding that will handle this.
That would be great! I am looking forward to test the new version since that improvement is really critical in my case. Once again congratulations for this fantastic job!
Seconded :+1:
@ramnathv and @pssguy how were you using ichoropleth
in shiny
? Perhaps I misunderstand, but I thought rMaps
is not compatible with shiny
?
In shiny ichoropleth(Crime ~ State, data = subset(violent_crime, Year == 2010), legend=TRUE, ncuts=7) ncuts works.
Great work I have the crudest of examples working in Shiny, but the legend appears to be absent Looking forward to an example where the various methods are shown starting with
and then showing how to set scope, fill, data, legend etc.etc.
On a side note, I have a column in my data.frame called Asian so that
if I have from ui.R an input$race of "Asian" how can I utilize that in the ichoropleth function?