【发布时间】:2021-04-29 20:30:09
【问题描述】:
我正在使用officer 在 R 中生成一个 powerpoint 演示文稿,然后将其转换为 PDF,以便用户可以在闪亮的 golem 应用程序中预览幻灯片。但是在引用this thread 和this SO answer to a similar question 之后,我仍然不太确定如何实现这一点。我能够在 iframe 内显示位于 inst/app/www 的外部 PDF,但不确定如何为应用程序本身生成的 PDF 执行此操作。
这是我的 app_server.R 文件中的相关代码 sn-p:
output$preview <- renderUI({
# Creates rpptx object with one slide
preview_rpptx <- add_title_slide(x = NULL, title = input_list[["title"]])
# Creates www/ directory if it doesn't exist
if (!dir_exists("www")) dir_create("www")
# Generates .pptx file
pptx_file_path <- file_temp("preview", tmp_dir = "www", ext = ".pptx")
print(preview_rpptx, pptx_file_path)
# Converts .pptx to .pdf
pdf_file_path <- file_temp("preview", tmp_dir = "www", ext = ".pdf")
convert_to_pdf(path = pptx_file_path, pdf_file = pdf_file_path)
tags$iframe(style = "height:600px; width:100%", src = str_sub(pdf_file_path, 5))
}
运行应用程序时,我在 iframe 中收到“未找到”错误。但是我可以看到在 www/ 目录中正确生成了 PDF 文件。
【问题讨论】:
-
如果您想以比 iframe 方式更漂亮的方式嵌入 pdf,我可以向您展示如何使用 pdfobject 库。