【发布时间】:2020-05-02 18:15:12
【问题描述】:
我想在我闪亮的应用程序中创建一个下载按钮,以下载使用 chartJSRadar 创建的反应图。我无法解决这个问题!
由于我已经通过互联网上记录的问题,我无法解决它,一直收到一个空的 png。按照建议 (Save plots made in a shiny app), https://groups.google.com/forum/#!msg/shiny-discuss/u7gwXc8_vyY/IZK_o7b7I8gJ
我建立了一个函数......
所以我的代码是一个示例代码:
ui.R:
library(radarchart)
shinyUI(pageWithSidebar(
headerPanel('Radarchart Shiny Example'),
sidebarPanel(
checkboxGroupInput('selectedPeople', 'Who to include',
names(radarchart::skills)[-1], selected="Rich")
),
mainPanel(
chartJSRadarOutput("plot1", width = "450", height = "300"), width = 7,
radioButtons(inputId = "var3", label = "Select the file type", choices = list("png", "pdf")),
downloadButton('downloadPlot', 'Download Plot')
)
))
服务器.R
library(radarchart)
shinyServer(function(input, output) {
output$plot1 <- renderChartJSRadar({
chartJSRadar(skills[, c("Label", input$selectedPeople)],
maxScale = 10, showToolTipLabel=TRUE)
})
plot2 <- function(){
chartJSRadar(skills[, c("Label", input$selectedPeople)],
maxScale = 10, showToolTipLabel=TRUE)
}
output$downloadPlot <- downloadHandler(
filename = "Shinyplot.png",
content = function(file) {
png(file)
plot2()
print(plot2())
dev.off()
})
})
【问题讨论】:
标签: r download chart.js shinyapps radar-chart