gpt4 book ai didi

r - 在 Rmd 文件中添加下载按钮但不显示表格

转载 作者:行者123 更新时间:2023-12-04 10:40:29 27 4
gpt4 key购买 nike

我能够显示表格并使用数据表 DT 库添加下载链接,例如

mtcars %>% DT::datatable(extensions = 'Buttons', 
options = list(dom = 'Bfrtip',
pageLength = 200,
buttons = list('copy', 'csv', 'excel')))

但是,我没有使用 mtcars,我使用的是大量 csv 训练数据,最终用户希望能够下载到 csv。

上面的 block ,当与我的真实数据一起使用时会给出一条消息:

It seems your data is too big for client-side DataTables. You may consider server-side processing: https://rstudio.github.io/DT/server.html

有没有其他方法可以提供下载按钮而不尝试实际显示表格(从而遇到内存问题)?

最佳答案

如果您只想向 Rmd 文档添加一个下载按钮,您可以使用 shiny::downloadHandlerruntime: shiny。例如,此 Rmd 将 mtcars 下载为 .csv 文件:

---
title: "Download .csv"
runtime: shiny
output: html_document
---

```{r, echo=FALSE}

## data (possibly a reactive expression)
myData <- mtcars

## create downloadButton in Rmd document
downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep = "")
},
content = function(file) {
write.csv(myData, file)
},
outputArgs = list(label = "Download .csv")
)

```

关于r - 在 Rmd 文件中添加下载按钮但不显示表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59959713/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com