I'm trying to download a pdf that I've created in a R backend using rmarkdown, but I'm not sure how to retrieve it back via HTTP, if that's even possible. I'm using Angular6 in the front-end and I'm just using basic GET/POST methods to communicate with my backend.
Here is some code related to this question:
Backend code (R):
EXPORT <- function(results){
library(rmarkdown)
library(knitr)
rmarkdown::render("genepanel.Rmd", output_format = "pdf_document", params = list(results = results))
}
Front-end code (Angular TypeScript):
this.http.post(environment.API + '/R/EXPORT/json', results)
.subscribe(result => console.log(result));
I don't get any HTTP error when calling the service and the pdf is generated if I manually run the code in the server.
Thanks in advance!
You should call the API without the /json
postfix. You will see an index generated resources and the pdf file should be in there.
Your client should check the Location
response header from the POST request to /R/EXPORT
which will contain the location of the session, and you can get the pdf from there.