0

Hi all, I want to add download option in R plumber api,where a R markdown report will be download as word file.please let me know how to do it in plumber. I get some code,but its not working

#* @serializer contentType list(type="application/octet-stream")
#* @get /word
function(team, res){
  
  res$setHeader("Content-Disposition", "attachment; filename=report.docx")
  
  tmp <- tempfile()
  
  render("test.Rmd", tmp, output_format = "word_document",
         params = list(team = team))
  
  readBin(tmp, "raw", n=file.info(tmp)$size)
}
  • 1
    I don't see a call to `library(rmarkdown)` or `library(plumber)`, so it seems likely there is more to this file than you've provided. Or is that your problem? You say it is not working but don't say how it's not working. Are there errors/warnings? (That's either on the R console if testing live, or in the server's log files if running on some server; or in the web page, if you're getting anything specific there such as HTTP 404 or such.) – r2evans Nov 06 '20 at 05:51
  • my target is this "I want to add download option in R plumber api,where a R markdown report will be download as word file."..if you can suggest any other code ? i have called library..thats not the issue ..i need a download button on it – Sabyasachi Datta Nov 06 '20 at 06:01
  • What you ask is not very clear. Do you mean I want the web browser ask for saving result (docx file) when accessing url or I want the web browser display a button that when clicked will download file ? For first case we need to fiddle returned headers, for the second it will be in two steps. One call to the api to get an html displaying a button that in turn will call another api function that will render file and force download (that is first case) – Billy34 Nov 06 '20 at 08:45
  • yes the second one..can share some example of the second one?? – Sabyasachi Datta Nov 06 '20 at 10:03
  • its in the doc https://www.rplumber.io/reference/include_file.html – Bruno Tremblay Nov 06 '20 at 13:10
  • My point (first comment) is that it is hard for us to distinguish sometimes between an actual omission that is causing the problem and just the OP abbreviating the code. While it might seem obvious to you where the problem is, without a *reproducible example*, it is not obvious to us (there are plenty of questions on SO where the user does not understand the need for things like that, where perhaps my comment could have been sufficient). – r2evans Nov 06 '20 at 14:28

0 Answers0