【发布时间】:2021-06-18 00:04:43
【问题描述】:
我有一个围绕 {pagedreport} 包(pagedown 的附加组件)构建的 rmarkdown 文件。这会创建一个 html,然后他们使用 pagedown::chrome_print 将 html 转换为 pdf。
当我在 rmarkdown 文件中手动输入参数时,我的 rmarkdown 文件按计划工作,但我希望能够从闪亮的应用程序中选择我的参数。
我目前已经尝试过这种方法
output$report <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = "new_report.pdf",
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path("../temp/", "myRmarkdown.Rmd")
file.copy("myRmarkdown.Rmd", tempReport, overwrite = TRUE)
# Set up parameters to pass to Rmd document
params <- list(A = input$A, B = input$B)
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
library(rmarkdown)
render(tempReport, params = params,
envir = new.env(parent = globalenv()))
}
我得到了结果:
Output created: MyRmarkdown.html
但没有创建 pdf。 Pagedown 使用 chrome_print 进行转换 - 这是在 Rmarkdown 的 yaml 中。
这是我的 Rmarkdown 文件的 YAML
output:
pagedreport::paged_windmill:
img_to_dark: TRUE
logo_to_white: TRUE
knit: pagedown::chrome_print
#toc: TRUE
toc-title: "Table of Contents"
#toc_depth: 1
main-color: "#264653"
secondary-color: "#2a9d8f"
google-font: TRUE
main-font: "Raleway"
header-font: "Roboto"
params:
A: NA
B: NA
editor_options:
markdown:
wrap: 72
我知道 shiny 和 chrome_print() 之间存在问题,您需要在其中添加 chrome_print(..., async = TRUE),但我不知道在我的闪亮应用中将此参数放在哪里?
【问题讨论】:
-
我编写了一个演示 Shiny 应用程序来展示如何在 Shiny 中使用
pagedown::chrome_print(),请参阅 github.com/RLesur/chrome_print_shiny。
标签: r shiny r-markdown pagedown