Shiny中的html小部件之间的交互

Shiny中的html小部件之间的交互

本文介绍了R Shiny中的html小部件之间的交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用多个html小部件的R Shiny应用程序,特别是 networkD3 d3heatmap chorddiag .

I am developing an R shiny application that uses several html widgets, notably networkD3, d3heatmap and 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..

非常感谢您的帮助!

# 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已在版本0.3 ,它与v3版本的D3(chorddiagd3heatmap似乎使用的版本)不兼容. htmlwidgets是驱动上述软件包的基础软件包,它仅使用依赖关系的最新版本,因此使用同一库的冲突版本的htmlwidget不能同时工作.在此处进行检查,以开始有关此问题的讨论.

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. 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. Check here for a starting point of discussion about this problem.

您有一些可能的选择,尽管它们都不是很好的选择...

You have a few possible options, though none of them are great...

  1. networkD3还原为版本< 0.3,因此它也使用D3v3

  1. revert networkD3 to a version < 0.3 so that it also uses D3v3

chorddiag开发人员 d3heatmap开发人员升级到D3v4

lobby for the chorddiag developers and the d3heatmap developers to upgrade to D3v4

大堂游说法具有冲突的JavaScript依赖项

lobby for the htmlwidgets developers to come up with a robust way of dealing with conflicting JavaScript dependencies

这篇关于R Shiny中的html小部件之间的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:42