ramnathv / rMaps

Interactive Maps from R
http://rmaps.github.io
390 stars 194 forks source link

Custom ichoropleth not displaying on Mac but on linux #34

Open ekstroem opened 10 years ago

ekstroem commented 10 years ago

Hi all,

I need a bit of help trying to figure out why I get the correct output when running on linux but almost no output when running the same script on Mac.

When I run this code on my Mac in RStudio I only get the legend but no map.

library(rMaps)
options(rcharts.cdn = TRUE)
options(RCHART_WIDTH = 700, RCHART_HEIGHT = 700)

indata <- read.table("middelleveltid.txt", col.names=c("kommune", "life"), as.is=TRUE, na.string="..")
indata[is.na(indata)] <- 0
indata$extra <- 1:99
indata$year <- rep(2010, nrow(indata))
indata$KOMNAVN <- indata$kommune
indata$name <- indata$kommune

# d1 <- ichoropleth(life ~ name, ncuts=5, data = indata, map='states', animate='year')

d1 <- ichoropleth(life ~ name, ncuts=5, data = indata, map='states')
d1$set(
  geographyConfig = list( dataUrl = "/home/claus/sandbox/dk_kom.json" ),
  scope = 'states',
  setProjection = '#! function( element, options ) {
           var projection, path;
           projection = d3.geo.mercator()
           .center([10, 56]).scale(element.offsetWidth*9)
           .translate([element.offsetWidth / 2, element.offsetHeight / 2]);
           path = d3.geo.path().projection( projection );
           return {path: path, projection: projection};
       } !#'
)
d1

If I instead save the plot instead of just viewing by

If I run the same code on my Ubuntu machine it just appears to work. Any clues?

Claus

ekstroem commented 10 years ago

Oh I might add ...

If I run the standard example

library(rMaps)
d2 <- ichoropleth(Crime ~ State, data = violent_crime[violent_crime$Year==2010,])

then I get the correct output in RStudio on Mac.

ramnathv commented 10 years ago

Can you do the following, so that it is easier for me to help debug?

  1. Save the chart to HTML using d1$save('index.html', cdn = TRUE)
  2. Upload index.html and dk_kom.json to a gist.

If you dont want dk_kom.json to be public, you can zip up the html and json files and email them to me so that I can take a look.

ekstroem commented 10 years ago

Thanks for looking at this. The files can be found at http://www.biostatistics.dk/rMaps/index.html and http://www.biostatistics.dk/rMaps/dk_kom.json

ramnathv commented 10 years ago

The relative link to dk_kom.json in the html file is incorrect. Can you update it in index.html so that it points to the correct dk_kom.json path?

ekstroem commented 10 years ago

Done. Changed the dataurl to ./dk_kom.json

ramnathv commented 10 years ago

I am able to view your html on a Mac in all browsers (Chrome/Firefox/Safari). I am not really sure what is happening at your end. Can you try and make sure you have the latest versions of all browsers?

Another thought that came to me is that I may not have updated the datamaps js files local to rCharts, which might be the interfering. Can you check if the charts show up when you save it with the option cdn = TRUE?

ekstroem commented 10 years ago

Have the latest version of all browsers so not that.

When saving with option cdn=TRUE I can see the map so that fixed that. Cheers!

However, if I want to weave it into a document I would type d1$print('chart4', include_assets = TRUE)- and that does not produce anything when I use knit2html("filename").

On a possibly related note: when I just print the ichoropleth object d1 in RStudio I still just get the legend in the viewer.

ramnathv commented 10 years ago

I will investigate this over the weekend. I think the fix is just updating the local js/css assets for datamaps.