Graphs cannot be drawn in xlsx files with the r language openxlsx package run on docker

I want to use the openxlsx package to create an xlsx file containing graphs on docker / shinyserver.

First, I checked if I could create an xlsx file containing graphs on docker. I ran r-base on docker with the following command.

docker run -ti --rm r-base bash

openxlsx

After installing openxlsx packages, I executed the following openxlsx_test.R file with the following command.

Rscript --verbose openxlsx_test.R
library(openxlsx)

## Create a new workbook
wb <- createWorkbook()
addWorksheet(wb, "Sheet1")

#Plot example
plot(iris[, 1], iris[, 2])

#Insert
insertPlot(wb, 1, width = 5, height = 3.5, fileType = "png", units = "in")

## Save workbook
saveWorkbook(wb, "Test.xlsx", overwrite = TRUE)

However, the following error occurred and the xlsx file could not be created. However, the Rplots.pdf file was generated.

running
  '/usr/lib/R/bin/R --no-echo --no-restore --file=openxlsx_test.R'

Error in insertImage(wb = wb, sheet = sheet, file = fileName, width = width,  : 
  File does not exist.
Calls: insertPlot -> insertImage
Execution halted

Doing the same in R on Windows will successfully draw the graph in the xlsx file.

I'm not familiar with Linux or docker so I'm not sure, but I think it's because docker doesn't have a graphics device, but I don't know the solution.

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.