Sankey networkD3 not working with rCharts

402 views
Skip to first unread message

Ben Porter

unread,
Mar 21, 2015, 5:05:27 PM3/21/15
to shiny-...@googlegroups.com
First off, I have to say how much I love Shiny.  Thanks for building it and maintaining it so well!  Now on to my problem...

I can create either a Sankey plot from the networkD3 package, or an nPlot from rCharts, but not both.  Error message in the log of the browser says, "Uncaught TypeError: undefined is not a function".  The longer, more detailed description of the issue is at this link on stackoverflow. Let me know if I should put all of that detail here too and I'll be happy to.  

Here is my code for you to replicate at home.  Just comment out line 30, ",showOutput("plot_nvd3", "nvd3")" you'll see how the Sankey Plot starts to work.

library(shiny)
library
(shinydashboard)
library
(rCharts)
library
(RCurl)
library
(networkD3)

data
(MisLinks)
data
(MisNodes)

URL
<- "https://raw.githubusercontent.com/christophergandrud/d3Network/sankey/JSONdata/energy.json"
Energy <- getURL(URL, ssl.verifypeer = FALSE)
EngLinks <- JSONtoDF(jsonStr = Energy, array = "links")
EngNodes <- JSONtoDF(jsonStr = Energy, array = "nodes")

ui
<- dashboardPage(
 
  dashboardHeader
(title = "Test"),
  dashboardSidebar
(
    sidebarMenu
(
      menuItem
("A rChart Multibar", tabName = "rChart-multibar"),
      menuItem
("B networkD3 Sankey", tabName = "networkD3-sankey"),
      menuItem
("C networkD3 Force", tabName = "networkD3-force")
   
)
 
),
  dashboardBody
(
    tabItems
(
     
      tabItem
(tabName = "rChart-multibar", h2("A rChart")
             
# comment out the following line, then the Sankey will work
             
,showOutput("plot_nvd3", "nvd3")
     
),
     
      tabItem
(tabName = "networkD3-sankey",h2("B networkD3 Sankey")
             
,sankeyNetworkOutput("networkPlot")
     
),  
     
      tabItem
(tabName = "networkD3-force",h2("C networkD3 Force")
             
,forceNetworkOutput("force")
     
)
   
)
     
 
)
)

server
<- function(input, output) {
 
  output$plot_nvd3
= renderChart({
   
   
### Works in the browser, but not in the viewer window
    hair_eye_male
<- subset(as.data.frame(HairEyeColor), Sex == "Male")
    nvd3_chart
<- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male,
                type
= 'multiBarChart')
    nvd3_chart$addParams
(width = 800, height = 400, dom = "plot_nvd3")
   
return(nvd3_chart)
   
 
})  
 
  output$networkPlot
<- renderSankeyNetwork({
    sankeyNetwork
(Links = EngLinks, Nodes = EngNodes,
                 
Source = "source", Target = "target",
                 
Value = "value", NodeID = "name",
                  width
= 700, fontsize = 12, nodeWidth = 30)
 
})
 
  output$force
<- renderForceNetwork({    
    forceNetwork
(Links = MisLinks, Nodes = MisNodes, Source = "source",
                 
Target = "target", Value = "value", NodeID = "name",
                 
Group = "group")
 
})
 
}

shinyApp
(ui, server)

Thanks! 
Ben

Joe Cheng

unread,
Mar 23, 2015, 7:16:33 PM3/23/15
to Ben Porter, shiny-...@googlegroups.com
I think this is happening because both networkD3 and rCharts are bringing in the d3 library, and they are conflicting.

We've created a standard way of incorporating JavaScript dependencies like this in the htmltools library; networkD3 uses this but rCharts does not. Ramnath, the author of rCharts, is working on an rCharts2 package that will use htmltools-based dependencies, which should fix this. (Or at least, get us to the next error message...)

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/57e2a645-518a-4538-b34b-3a536fcee1d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Porter

unread,
Mar 23, 2015, 10:15:18 PM3/23/15
to shiny-...@googlegroups.com, benjamin...@gmail.com
Thanks Joe.  That makes sense. 

Federico Urban

unread,
Sep 2, 2015, 3:57:39 AM9/2/15
to Shiny - Web Framework for R
Actually the same "incompatibility" occurs also with d3heatmap and scatterD3 package.
Reply all
Reply to author
Forward
0 new messages