从闪亮的应用程序代码中下载绘制的sankey图时遇到问题。我实际上是基于R文档进行输入的,但是在这里一切正常! 这是代码
ui <- fluidPage( downloadButton('d', 'Download graph') )
server <- function(input, output) {
output$d <- downloadHandler(
filename = function() {
'SankeyPlot.png'
},
content = function(file) {
png(filename = "SankeyPlot.png",width = 550,height = 480,units = px,type = 'png')
print(sankeyNetworkOutput("splot"))
dev.off()
},
contentType = 'image/png'
)
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
SankeyNetworkD3返回一个'networkD3'小部件,而不返回png。我认为您应该使用html小部件加载程序或类似功能(如SaveNetwork)。
答案 1 :(得分:0)
Something like that:
library(networkD3)
library(shiny)
ui <- fluidPage(
downloadButton('d', 'Download graph'),
simpleNetworkOutput("network")
)
server <- function(input, output) {
network <- reactive({
src <- c("A", "A", "A", "A",
"B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J",
"E", "F", "G", "H", "I")
networkData <- data.frame(src, target)
simpleNetwork(networkData)
})
output$network <- renderSimpleNetwork({
network()
})
output$d <- downloadHandler(
filename = function() {
'SankeyPlot.html'
},
content = function(file) {
saveNetwork(network(), file)
}
)
}
shinyApp(ui = ui, server = server)
答案 2 :(得分:-1)
如果包含您的代码@StéphaneLaurent,这就是我得到的