如何使用Shiny中的下载按钮? [英] How to use the download button in Shiny?
本文介绍了如何使用Shiny中的下载按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Shiny中的下载按钮下载csv
文件.该文件将使用辅助r脚本中的参数创建.
I want to download a csv
file using the download button in Shiny. The file would be created using the parameters from a secondary r script.
###SERVER
output$downloadData <- downloadHandler({
filename = function() {
paste('data-', Sys.Date(), '.csv', sep='')
}
content = function(file) {
csv_write<-array(0,dim=c(length(GHI_D),15))
csv_write<-cbind(GHI_Data$timeStamp,GHI_D,POA_OBS_T,POA_model_T,POA_model_FT,POA_OBS,DNI_model,DHI,tracking_angle,incidence_angel_T,Backtracking_angle,SunAz,SunEl,Kt,DNI,DDNI,incidence_angel,DHI_model,DHI_model_T,Eb,Eb_T)
write.csv(csv_write,row.names=FALSE, na="")
write.csv(csv_write,row.names=FALSE, na="")
}
})
### UI
downloadButton('downloadData', 'Download CSV Report', style="display: block; margin: 0 auto; width: 230px;color: black;")
推荐答案
我认为您的代码存在的问题是您正试图从一个下载按钮下载两个CSV.您有两个名为csv_write的变量和两个write.csv调用.一个最小的工作示例如下:
I think the problem with your code is that you are trying to download two CSV's from one downloadbutton. You have two variables called csv_write, and two write.csv calls. A minimal working example would look like:
library(shiny)
server <- shinyServer(function(input, output, session) {
output$downloadData <- downloadHandler(
filename = function() {
paste("dataset-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
write.csv(mtcars, file)
})
})
ui <- shinyUI(fluidPage(
downloadButton('downloadData', 'Download data')
))
shinyApp(ui=ui,server=server)
这篇关于如何使用Shiny中的下载按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文