r Shiny-下载uioutput作为pdf

发布于 2025-02-03 23:33:04 字数 875 浏览 2 评论 0原文

我正在尝试创建一个在我的Shiny应用中与下载者一起使用的R Markdown文件。在R标记中,我只需要一个简单的UIOutput。以下是我尝试将其传递到降价文件中的方式。

在服务器中:

output$myOutput <- renderUI({
    ... # the output that needs to be printed 
})

output$downloadChart <- downloadHandler(
    filename = "report.pdf",
    content = function(file) {
      tempReport <- file.path(tempdir(), "report.Rmd")
      file.copy("report.Rmd", tempReport, overwrite = TRUE)
      
      params <- list(report = output$myOutput)
      
      rmarkdown::render(tempReport, output_file = file, params = params, envir = new.env(parent = globalenv()))
    }
)

report.rmd

---
title: "report"
output: pdf_document
params:
  report: NA
---

```{r}
params$report```

使用上述代码时,下载了HTML文件。我真的不明白为什么这是因为我已经指定了PDF。这不是制作可下载文件的正确方法吗?我很新鲜。任何帮助将不胜感激!

I am trying to create a R markdown file that works with the downloadHandler in my shiny app. In the r markdown I just need a simple uiOutput. Below is how I attempted to pass it into the markdown file.

In server:

output$myOutput <- renderUI({
    ... # the output that needs to be printed 
})

output$downloadChart <- downloadHandler(
    filename = "report.pdf",
    content = function(file) {
      tempReport <- file.path(tempdir(), "report.Rmd")
      file.copy("report.Rmd", tempReport, overwrite = TRUE)
      
      params <- list(report = output$myOutput)
      
      rmarkdown::render(tempReport, output_file = file, params = params, envir = new.env(parent = globalenv()))
    }
)

report.Rmd

---
title: "report"
output: pdf_document
params:
  report: NA
---

```{r}
params$report```

When the code above is used, a HTML file is downloaded. I don't really understand why is this so since I already specified PDF. Is this not the right way to produce a downloadable file? I'm very new to R shiny. Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文