如何在闪亮的 golem 应用程序中显示动态生成的 PDF 文件

问题描述

我正在使用 officer 在 R 中生成一个 powerpoint 演示文稿,然后将其转换为 PDF,以便用户可以在闪亮的 golem 应用程序中预览幻灯片。但是在参考了 this threadthis SO answer to a similar question 之后,我仍然不太确定如何实现这一点。我可以在 iframe 内显示位于 inst/app/www 中的外部 PDF,但不确定如何对应用程序本身内部生成的 PDF 执行此操作。

这是我的 app_server.R 文件中的相关代码片段:

  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",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文件。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)