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..
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)
devtools::install_github("mattflor/chorddiag")
. Thanks for your help! – Fendersonheatmap
andchord
together. Only addingsankey
makes the page go blank. – Bract