error in png() Rmarkdown Word with Plumber API

I am creating a Plumber API to generate a MS Word document with images, however, I get the following error in Swagger

"message": "\u001b[1m\u001b[33mError\u001b[39m in `png()`:\u001b[22m\n\u001b[33m!\u001b[39m unable to start png() device\n"

This is my plumber function plumber.R

#* @serializer contentType list(type="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
#* @get /word
  tmp <- getwd()
  render("test_report.Rmd", tmp, output_format = "word_document",
         params = list(team = team))

  readBin(paste0(tmp, ".docx"), "raw",, ".docx"))$size)

This is the Rmd file test_report.Rmd

title: test
output: html_document
  team: NA

`r params$team`

```{r cars}

```{r, echo=FALSE}

To run the API

pr("plumber.R") %>%

I am using the correct serializer, as without including the plot() the API works. What is the problem?

There seems to be an issue with the opening of the png device. Without knowing more about your system configuration, help is difficult to provide. The code below successfully returned a docx file.

#* @serializer contentType list(type="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
#* @get /word
function(team = "BOB"){
  tmp <- getwd()
  rmarkdown::render("test_report.Rmd", tmp, output_format = "word_document",
         params = list(team = team))
  path <- paste0(tmp, ".docx")
    value = readBin(path, "raw",$size),
    filename = "results.docx"

r - Error : Unable to start png() device - Stack Overflow

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.