r语言 - 如何在 rshiny 中以 .csv 格式下载编辑后的数据帧?



我正在开发一个Rshiny应用程序,在其中我编辑了数据帧的内容并以.csv格式下载了编辑后的数据帧。但是下载的文件不是.csv格式。任何人都可以帮助我解决这个问题吗?

output$downloadData <- downloadHandler(filename = function() {paste(Sys.time(), 'Edited Table.csv', sep='') } ,content = function(file) {write.csv(sample_data(), file, row.names = FALSE)})

这是使用的代码。提前感谢!!

我试图用一个例子复制你的结果,但我无法重现你的问题。这是一个自给自足的RShiny应用程序,可以下载.csv文件。确保您的应用遵循此模板,如果问题仍然存在,请提供相同的可重现示例。

library(shiny)
ui <- fluidPage(
downloadButton("downloadData", "Download")
)
server <- function(input, output) {
# Your Sample dataset
sample_data <- reactive({mtcars})
output$downloadData <- downloadHandler(
filename = function() {
paste(Sys.time(), ' Edited Table.csv', sep='')
},
content = function(file) {
write.csv(sample_data(), file, row.names = FALSE)
}
)
}
shinyApp(ui, server)

最新更新