Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems while reproducing Sankey chart example with d3_sankey

I am trying to reproduce simple example with rCharts library to plot sankey chart. I found this example from scratch and tried to reproduce it, however, I came up with some problems.

Firstly I have tried running this code without nothing. Then I found out and realized, that I need d3_sankey in my computer. So, I have downloaded it from here and copied to C:\Users\adomas\Documents\R\win-library\3.0\rCharts\libraries\widgets\d3_sankey.

Then I've tried that unchanged code once more and still got the following error:

Error in file(con, "r") : cannot open the connection In addition: Warning message: In file(con, "r") : cannot open file '/config.yml': No such file or directory

Since that didn't help too, I have tried changing paths from: sankeyPlot$setLib('libraries/widgets/d3_sankey') sankeyPlot$setTemplate(script = "libraries/widgets/d3_sankey/layouts/chart.html")

to

sankeyPlot$setLib('C:/Users/adomas/Documents/R/win-library/3.0/rCharts/libraries/widgets/d3_sankey') sankeyPlot$setTemplate(script = "C:/Users/adomas/Documents/R/win-library/3.0/rCharts/libraries/widgets/d3_sankey/layouts/chart.html")

However, this time, the blank screen in Viewer appeared but no actual Sankey graph and I got the following in console: Warning message: In readLines(file, warn = warn, ...) : invalid input found on input connection 'C:/Users/adomas/Documents/R/win-library/3.0/rCharts/libraries/widgets/d3_sankey/layouts/chart.html

I have tried changing paths and etc, but still something is wrong. And I am not sure if I need to use sankeyPlot$setTemplate at all. I want to use Sankey chart in my shiny application, but firstly I want to reproduce simply in R. Suggestions would help a lot!

Versions of libraries: rCharts_0.4.2 igraph_0.7.0 R version: 3.0.2

EDITED: I have tried this code on different system. And everything works there. Versions of libraries and R are the same and I've copied same documents and just specified full path. I have tried that again on my own computer, but still got the same error yet.

like image 581
adomasb Avatar asked Feb 24 '14 11:02

adomasb


2 Answers

I've experienced the same issues. The solution for me was to upgrade rCharts :

devtools::install_github("rCharts", "ramnathv")

Second, I didn't include the sankeyPlot$setTemplate() line.

Finally, the path in $setLib() should be a direct path (as discribed in the solution of @adomasb or the following line can be used to link directly to the original github:

sankeyPlot$setLib('http://timelyportfolio.github.io/rCharts_d3_sankey/libraries/widgets/d3_sankey')

A downside of this last approach is that internet is always required to run the script.

like image 79
Timror Avatar answered Sep 29 '22 14:09

Timror


Alright, eventually it works as it should be.

I just rebooted my system and that's it. However, if anyone would come up with same problem, just be sure you specify direct path, where you placed all necessary files for d3_sankey. Therefore, you rather use sankeyPlot$setLib('C:/Users/adomas/Documents/R/win-library/3.0/rCharts/libraries/widgets/d3_sankey')

This is wonderful chart type. Good luck!

like image 24
adomasb Avatar answered Sep 29 '22 15:09

adomasb