-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dateInput and dateRangeInput stop working when a Sankey Network is rendered #214
Comments
Thanks for the reproducible example! I can confirm that there seems to be some conflict between specifically library(shiny)
library(networkD3)
ui <- fluidPage(
mainPanel(
dateInput("date", "Date: "),
forceNetworkOutput("plotForceGraph")
)
)
server <- function(input, output) {
output$plotForceGraph <- renderForceNetwork({
data(MisLinks)
data(MisNodes)
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, zoom = TRUE)
})
}
shinyApp(ui = ui, server = server) but does not function as expected when included on a page with a library(shiny)
library(networkD3)
ui <- fluidPage(
mainPanel(
dateInput("date", "Date: "),
sankeyNetworkOutput("plotSankeyGraph")
)
)
server <- function(input, output) {
output$plotSankeyGraph <- renderSankeyNetwork({
URL <- paste0('https://cdn.rawgit.com/christophergandrud/networkD3/',
'master/JSONdata/energy.json')
energy <- jsonlite::fromJSON(URL)
sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
Target = 'target', Value = 'value', NodeID = 'name',
units = 'TWh', fontSize = 12, nodeWidth = 30)
})
}
shinyApp(ui = ui, server = server) I suspect there's some JavaScript and/or CSS conflict between the two, but that will take some effort to track down exactly. |
I narrowed this down to the sankeyNetwork.js script adding a demo the problem... <!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker3.min.css'>
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'>
</head>
<body>
<input type="text" class="date-picker form-control">
<br>
<svg width="100px" height="100px">
<rect height="50" width="50" style="fill: rgb(199, 199, 199); cursor: move;">
</rect>
</svg>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.js'></script>
<script>$('.date-picker').datepicker({});</script>
<script>
d3.select("svg rect")
.append("title")
.append("foreignObject")
.append("xhtml:body")
.html("<pre>\u2192 Wind\n289 TWh</pre>");
</script>
</body>
</html> demo avoiding the problem... <!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker3.min.css'>
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'>
</head>
<body>
<input type="text" class="date-picker form-control">
<br>
<svg width="100px" height="100px">
<rect height="50" width="50" style="fill: rgb(199, 199, 199); cursor: move;">
</rect>
</svg>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.js'></script>
<script>$('.date-picker').datepicker({});</script>
<script>
d3.select("svg rect")
.append("title")
.append("foreignObject")
.html("<pre>\u2192 Wind\n289 TWh</pre>");
</script>
</body>
</html> PR #180 is when this was implemented, and issue #175 (particularly this comment) has some background on how/why this was implemented, but I don't see anything that says explicitly why the |
Hopefully this will fix. Thank you for the prompt responses! It wasn't working on IE11 (and maybe others) without the xhtml:body tag, but replacing with xhtml:pre did the job. |
It would be good to submit this issue upstream to bootstrap-datepicker also, since the structure... <foreignObject>
<xhtml:body>
<pre>
</pre>
</xhtml:body>
</foreignObject> inside an SVG is technically valid HTML/SVG as far as I can tell. |
It looks like bootstrap-datepicker is supporting such structure, while the problem is that d3.js is not appending the https://jsfiddle.net/9w31r03x/ This makes my PR #215 to fix the issue technically not correct because |
I still think just removing the |
For instance, if you simply comment out line 7 in the JS of your example, |
Yes and that's what PR #215 basically does, though currently in the wrong way. For completeness, I said it's "technically" not correct because in SVG 1.1 the foreignObject would need a way to know what type of markup is in it, and from the SVG 2 draft:
|
Sorry, somehow I must have misread PR #215 before... I thought it removed the |
Dear All, I see that this issue is known for quite some time now. I wanted to use the Sankey network in my application, but I also have several dateInputs which break down upon loading the Sankey plot. What do you think, can I expect a solution in the forseeable future. As I see the pull request has not been accepted yet. Thanks in advance! |
Looks like this is/will be finally fixed upstream with rstudio/shiny@3d11780 will close this issue once I have verified it |
This problem appears to be resolved in the upstream fix in |
I don't know whether it's a problem in networkD3 or in Shiny.
When first loading the page, no Sankey Network, the dateInput works. As soon as the Sankey Network (the simple one from the help example) is rendered, the dateInput stops working properly:
Using networkD3 0.4 and Shiny 1.0.5 (R 3.4.1).
The text was updated successfully, but these errors were encountered: