【问题标题】:How to download pdf generated with rmarkdown via HTTP using OpenCPU如何使用 OpenCPU 通过 HTTP 下载使用 rmarkdown 生成的 pdf
【发布时间】:2018-07-12 10:50:38
【问题描述】:

我正在尝试下载我使用 rmarkdown 在 R 后端创建的 pdf,但我不确定如何通过 HTTP 将其取回,如果可能的话。我在前端使用 Angular6,我只是使用基本的 GET/POST 方法与我的后端通信。

这里有一些与这个问题相关的代码:

后端代码(R):

EXPORT <- function(results){ library(rmarkdown) library(knitr) rmarkdown::render("genepanel.Rmd", output_format = "pdf_document", params = list(results = results)) }

前端代码(Angular TypeScript):

this.http.post(environment.API + '/R/EXPORT/json', results) .subscribe(result => console.log(result));

我在调用服务时没有收到任何 HTTP 错误,如果我在服务器中手动运行代码,则会生成 pdf。

提前致谢!

【问题讨论】:

    标签: r angular http r-markdown opencpu


    【解决方案1】:

    您应该调用不带 /json 后缀的 API。您将看到一个索引生成的资源,并且 pdf 文件应该在其中。

    您的客户端应该检查来自 POST 请求的 Location 响应标头到 /R/EXPORT,其中将包含会话的位置,您可以从那里获取 pdf。

    【讨论】:

      猜你喜欢
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-13
      • 2012-02-13
      • 2015-11-15
      • 2015-12-17
      相关资源
      最近更新 更多