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.
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"]
)
library(plumber)
#' @post /hello
#' @serializer csv
function(req, res) {
# <some r code>
as_attachment(mydataframe, filename = "myfile.csv")
No such @serializer registered: csv
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.