r语言 - Shiny Rmarkdown html download



在我的Rmarkdownfile中,我想下载我的.rmd作为html文件,但我得到以下错误。

警告:文件错误。无法打开连接。

我认为这是因为外部文件包含源(…),但我不知道为什么。在外部文件中,我连接到一个数据库。

---
output: 
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(rmarkdown)
source('R/load_data.R')
```
```{r}
output$export_btn<- downloadHandler(
filename = "report.html",
content = function(file) {
tempReport <- file.path(tempdir(), "test.Rmd")
file.copy("test.Rmd", tempReport, overwrite = TRUE)
out<-render(tempReport, html_document())
file.rename(out,file)
}
)
```

file传递给函数content = function(file)file是默认的R函数。你的意思是将filename传递给函数吗?

output$export_btn<- downloadHandler(
filename = "report.html",
content = function(filename) {
tempReport <- file.path(tempdir(), "test.Rmd")
file.copy("test.Rmd", tempReport, overwrite = TRUE)
out<-render(tempReport, html_document())
file.rename(out,filename)
}
)

最新更新