[英]Interaction between html widgets in R shiny
I am developing an R shiny application that uses several html widgets, notably networkD3 , d3heatmap and chorddiag .我正在开发一个 R 闪亮应用程序,它使用几个 html 小部件,特别是networkD3 、 d3heatmap和chorddiag 。
These widgets work fine separately.这些小部件单独工作正常。 However, using them in the same page leave a blank space where they are supposed to be.
但是,在同一页面中使用它们会在它们应该出现的地方留下空白。
Here is a reproducible code that shows the bug.这是显示错误的可重现代码。 Comment plots line in the UI and you will see plots appearing and disappearing..
在 UI 中注释绘图行,您将看到绘图出现和消失..
I thank you very much for your help!我非常感谢你的帮助!
# libraries
library(shiny)
library(d3heatmap)
library(chorddiag)
library(networkD3)
# Server
server <- function(input, output) {
# create heatmap
output$heatmap <- renderD3heatmap({
d3heatmap(mtcars, scale = "column", colors = "Spectral")
})
# create chord diagram
output$chord <- renderChorddiag({
m <- matrix(c(11975, 5871, 8916, 2868,1951, 10048, 2060, 6171, 8010, 16145, 8090, 8045,1013, 990, 940, 6907),
byrow = TRUE, nrow = 4, ncol = 4)
haircolors <- c("black", "blonde", "brown", "red")
dimnames(m) <- list(have = haircolors, prefer = haircolors)
groupColors <- c("#000000", "#FFDD89", "#957244", "#F26223")
chorddiag(m, groupColors = groupColors, groupnamePadding = 20)
})
# create sankey
output$sankey <- renderSankeyNetwork({
nodes=data.frame(ID=c("A","B","C","D","E"))
links=data.frame(source=c(1,2,3), target=c(3,4,4), value=c(12,15,29))
sankeyNetwork(Links = links, Nodes = nodes, Source = "source", Target = "target", Value = "value", NodeID = "ID")
})
}
# Ui
ui <- fluidPage(
sidebarLayout(
sidebarPanel("shiny shines"),
mainPanel(
# Comment these lines and you will see charts appear / disappear.
d3heatmapOutput("heatmap"),
chorddiagOutput("chord"),
sankeyNetworkOutput("sankey")
)
)
)
shinyApp(ui = ui, server = server)
networkD3
was updated to D3v4 in version 0.3 in. Feb. 2017, which is not compatible with v3 versions of D3, which is what chorddiag
and d3heatmap
appear to use. networkD3
在 2017 年 2 月的0.3 版中更新为 D3v4,这与 D3 的 v3 版本不兼容,而chorddiag
和d3heatmap
似乎使用了这种版本。 htmlwidgets
, which is the underlying package that drives the above packages, only uses the most recent version of a dependency, so htmlwidgets that use conflicting versions of the same library can not both work. htmlwidgets
是驱动上述包的底层包,它只使用最新版本的依赖项,因此使用同一库的冲突版本的 htmlwidgets 不能同时工作。 Check here for a starting point of discussion about this problem. 在这里查看有关此问题的讨论起点。
You have a few possible options, though none of them are great...您有几个可能的选择,尽管它们都不是很好...
revert networkD3
to a version < 0.3 so that it also uses D3v3将
networkD3
恢复为 < 0.3 的版本,以便它也使用 D3v3
lobby for the chorddiag
developers and the d3heatmap
developers to upgrade to D3v4为
chorddiag
开发人员和d3heatmap
开发人员升级到 D3v4 的游说
lobby for the htmlwidgets
developers to come up with a robust way of dealing with conflicting JavaScript dependencies游说
htmlwidgets
开发人员提出一种强大的方法来处理冲突的 JavaScript 依赖项
@CJYetman gave 3 options for dealing with this. @CJYetman 提供了 3 个处理此问题的选项。 Here's one more, which might be less work, though it's still unappealing: Rename the library used in
chorddiag
and d3heatmap
from d3
to something else, so that both version 3 of D3 (used by those two) and version 4 (used by networkD3
) can coexist on the same page.这里还有一个,虽然它仍然没有吸引力,但它的工作量可能会减少:将
chorddiag
和d3heatmap
使用的库从d3
重命名为其他内容,以便 D3 的第 3 版(由这两个使用)和第 4 版(由networkD3
)可以共存于同一页面。
A first pass at doing this for chorddiag
is here: https://github.com/dmurdoch/chorddiag .为
chorddiag
执行此操作的chorddiag
在这里: https : //github.com/dmurdoch/chorddiag 。 It renames the library to d3_3
.它将库重命名为
d3_3
。 This same change also appears to work for d3heatmap
;同样的变化似乎也适用于
d3heatmap
; see https://github.com/dmurdoch/d3heatmap .见https://github.com/dmurdoch/d3heatmap 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.