Open sanchez5674 opened 10 years ago
Hi,
I had some problems. Eventually I went from rCharts Sankeys to ggVis sankeys, which doesn't conflict with anything. What problems do you have?
Hi,
I took this piece of code from someone else to see if it would work:
require(shiny) require(rjson)
links <- matrix(unlist( rjson::fromJSON( file = "http://bost.ocks.org/mike/sankey/energy.json" )$links ),ncol = 3, byrow = TRUE)
nodes <- unlist( rjson::fromJSON( file = "http://bost.ocks.org/mike/sankey/energy.json" )$nodes )
links <- data.frame(links)
colnames(links) <- c("source", "target", "value")
links$source <- sapply(links$source, FUN = function(x) {return(as.character(nodes[x+1]))}) #x+1 since js starts at 0
links$target <- sapply(links$target, FUN = function(x) {return(nodes[x+1])}) #x+1 since js starts at 0
runApp(list( ui = pageWithSidebar( headerPanel('Test'), sidebarPanel( 'Test' ), mainPanel( showOutput('sankey', 'd3_sankey') ) ), server = function(input, output, session){
print(getwd())
output$Plot <- renderChart2({
sankeyPlot2 <- rCharts$new()
sankeyPlot2$setLib('d3_sankey')
sankeyPlot2$set(
data = links,
nodeWidth = 15,
nodePadding = 10,
layout = 32,
width = 960,
height = 500,
units = "TWh",
title = "Sankey Diagram"
)
return(sankeyPlot2)
}) } ))
I have copied the 'd3_sankey' directory to my root directory but eventhough the app "runs", the plot does not appear.
I was also thinking about moving to ggVis but it is not as colorful. Also, I like the tooltip feature in rCharts.
By the way, thanks for the VERY fast reply :)
Carlos
Just first reply was fast :) ... I am sorry, I don't have enough time recently to reproduce good example with sankey and shiny. However, if you are not satisfied with googleVis visualizations (I would be honest -- I am not too) even though they are more stable and easily created, I suggest you to check this blog post: http://www.r-bloggers.com/visualizing-website-pathing-with-sankey-charts/ . I haven't tried it inside shiny but I think is gonna work better than rCharts. Most important -- output looks much more better than googleVis. Moreover, that d3network library has few very cool network graphs which could be used in many different approaches. Hope it helped a little.
Hi,
I was able to get rCharts shankey + shiny to work. In any case, I think the d3network implementation makes it much simpler. Thanks for the info!
Hi,
Sorry to bother you but I'm having some issues including a Sankey plot into a Shiny app. I believe you succeeded at doing that so I was wondering if you could share the code.
Thanks in advance.
Carlos