【问题标题】:Shiny Rmarkdown html download闪亮的 Rmarkdown html 下载
【发布时间】:2021-02-04 19:03:25
【问题描述】:

在我的Rmarkdownfile 中,我想将我的.rmd 下载为html 文件,但出现以下错误。

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

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

---
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)
     }
    )
```

【问题讨论】:

    标签: r shiny r-markdown flexdashboard


    【解决方案1】:

    您正在将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)
         }
        )
    

    【讨论】:

    • 不,没关系,但是当我不获取 R/load_data.R 文件时,它工作正常???
    • 不确定。但是,如果它在您不采购时有效,那么您可能正在加载有冲突的东西?
    猜你喜欢
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 2021-11-22
    • 1970-01-01
    • 2017-06-29
    • 2020-04-30
    • 2016-02-03
    相关资源
    最近更新 更多