Search code examples
rdockergoogle-cloud-runplumber

No such @serializer registered: csv (Plumber)


I am using Plumber on Google Cloud Run through a docker image. Generally, it works fine, but now I am trying to use serializers to send files as attachments but it does not seem to work.

Dockerfile

This dockerfile is inspired on Mark Edmonson's guide: https://code.markedmondson.me/googleCloudRunner/articles/cloudrun.html

FROM trestletech/plumber
RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
  && apt-get install -y git-core
RUN ["install2.r", "remotes"]
COPY ["./", "./"]
ENTRYPOINT ["R", "-e", "pr <- plumber::plumb(commandArgs()[4]); pr$run(host='0.0.0.0', port=as.numeric(Sys.getenv('PORT')))"]
CMD ["api.R"]

(Plumber is installed from trestletech/plumber image, that is why it's not in the list of packages; otherwise, I would use RUN ["install2.r", "plumber", "remotes"])

R script (excerpt)

library(plumber)
#' @post /hello
#' @serializer csv
function(req, res) {

  # <some r code>

  as_attachment(mydataframe, filename = "myfile.csv")

Output

No such @serializer registered: csv

Solution

  • It seems that the Docker image I was using was outdated (last update was 3 years ago). I switched to this another image which is up-to-date. This fixed my issue.