timelyportfolio / rCharts_d3_sankey

rCharts implementation of d3 sankey plugin
54 stars 87 forks source link

invalid input found on input connection #3

Open adomasb opened 10 years ago

adomasb commented 10 years ago

Hi,

I am started using rCharts Sankey plots. And it really suits my needs. However, I have many problems. Because sometimes it works, sometimes doesn't.

So, firstly I would like to ask how should I correctly specify library path with setLib(). I have cloned this repo to my local and set it: sankeyPlot$setLib('C:/Users/adomasb/Documents/GitHub/rCharts_d3_sankey/libraries/widgets/d3_sankey') but I still get error: > sankeyPlot Warning message: In readLines(file, warn = warn, ...) : invalid input found on input connection 'C:\Users\adomasb\Documents\GitHub\rCharts_d3_sankey\libraries\widgets\d3_sankey/layouts/chart.html'

The only thing I get in Viewer is question mark (?).

timelyportfolio commented 10 years ago

Alright, let's try something a little different to see if it might work for you. If you can,

#get dev branch of rCharts
require(devtools)
install_github("rCharts","ramnathv",ref="dev")

Then once we have the newest branch, we can try something like this.

sankeyPlot$setLib("http://timelyportfolio.github.io/rCharts_d3_sankey")
#needed to satisfy dev branch and avoid an error
sankeyPlot$setTemplate(
  afterScript = "<script></script>"
)

Let me know how this works. Thanks for trying this thing. Suggestions always welcome.

adomasb commented 10 years ago

Hi,

yesterday I was so happy that actually it works at last, but I wanted to make sure firstly. So...

Firstly, it worked. I've tried on just script, then I've run it on shiny application and it worked too, like here: https://github.com/adomasb/sankeyNshiny. Then I tried it on my shiny app project, which is more complex and sophisticated and error occurred again: Warning in readLines(file, warn = warn, ...) : invalid input found on input connection 'http://timelyportfolio.github.io/rCharts_d3_sankey/layouts/chart.html' In the app, where sankey diagram should appear, only question mark (?) appears.

Then I tried again that sankeyNshiny app,which worked before, and I get the same error and same question mark...

Then I've tried testing a lot. Firstly, sankeyNshiny works again after closing and reopening rStudio. Therefore, I had a thought, that some libraries which I use on complex app do the thing. I have tried loading each library one by one and still simple app worked. Libraries list I use for my complex app: library(shiny) library(ggplot2) library(RPostgreSQL) library(shinyIncubator) library(plyr) library(rpart) library(RColorBrewer) library(rpart.plot) library(rCharts) library(reshape2)

So, I thought probably this isn't a case.

Then I thought that I use dimple charts in my complex app already, maybe that's the problem. After adding dimple diagram to sankeyNshiny app I realized that they both don't work in the same app (don't know why), only dimple appears. However, I am not getting error, just sankey diagram doesn't appear. After commenting dimple and rerunning, sankey appears. So, this isn't a case too.

I am feeling totally desperate so far and stuck. Unfortunately I cannot find any more examples with sankey diagram in shiny to test on my system. Only options is to use googleVis sankey diagram which just shown few days ago, however it is not that good as yours.

If you have any tips, just let me know.

timelyportfolio commented 10 years ago

I have a couple first guesses that I will work through this morning and the report back.

timelyportfolio commented 10 years ago

could you also do sessionInfo()?

timelyportfolio commented 10 years ago

Ok, looks like my first guess might be right. Please see my forked version of your sample (thanks for including). What I think is happening is we are loading two instances of d3.js which conflict, so I changed to manually add all the js/css combinations in ui.R.

...
tagList(
    singleton(
      tags$head(
        tags$script(src='assets/js/d3.v3.js', type = 'text/javascript', charset = 'utf-8'),
        tags$script(src='assets/js/sankey.js', type = 'text/javascript', charset = 'utf-8'),
        tags$script(src='assets/js/dimple.v1.1.5.js', type = 'text/javascript', charset = 'utf-8'),
        tags$link(rel = 'stylesheet', type = 'text/css', href = 'assets/css/sankey.css')
      )
    )
  )
...

If this does not work for you, there are other ways to handle this. @ramnathv is far more proficient with shiny than I am and might have some better ideas.

ramnathv commented 10 years ago

@adomasb Here is a simple way to fix your app.

From the root directory of your app, run the following piece of code. It downloads the d3_sankey folder from @timelyportfolio to your folder.

library(downloader)
tf <- tempfile(fileext = ".zip")
download("http://github.com/timelyportfolio/rCharts_d3_sankey/archive/gh-pages.zip", tf)
ex = tempdir()
unzip(tf, exdir = ex)
d3_sankey = file.path(ex, "rCharts_d3_sankey-gh-pages", "libraries", "widgets", "d3_sankey")
file.copy(d3_sankey, recursive = TRUE)

You need to make the following changes to the code in your app

The reason you are required to do this is possibly a bug in showOutput in not being able to handle rCharts libraries served online. I was able to get your code to produce a sankey plot in Shiny. So, if you are unable to get your app working even after making these changes, let me know and I can submit a pull request.

adomasb commented 10 years ago

Thanks for effort guys! AT LAST! image

We can see dimple and sankey diagrams in the same app! @timelyportfolio thank you very much for your suggestion. Actually, it didn't worked until I specify libraries and in ui.R added: mainPanel( tableOutput("table"), showOutput("sankey", ".", add_lib=F), showOutput("dimple", "dimple",add_lib=F) ) because I got ERROR: object 'LIB' not found all the time.

So, I need to implement this to normal app. However, I am not very good with js/css and your additional combinations don't say much to me. Is there any more elegant way to do the same? I am using navbarPage, so where should I put it? Maybe @ramnathv has suggestions? (BTW, thanks for your comment, I will use local folder rather than online).

emanuser commented 8 years ago

ramnathv, You are awesome, that code is exactly what I needed... shiny apps io was not playing very nicely

Thanks