From 40ba54a6663d2460b94e8d47ee2930125c5adfac Mon Sep 17 00:00:00 2001 From: Maximilian Muecke Date: Wed, 3 Jan 2024 15:17:34 +0100 Subject: [PATCH] refactor: update plumber example --- examples/plumber/Dockerfile | 23 ++++++++++++----------- examples/plumber/plumber.R | 10 ++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 examples/plumber/plumber.R diff --git a/examples/plumber/Dockerfile b/examples/plumber/Dockerfile index 43916b7..443e25d 100644 --- a/examples/plumber/Dockerfile +++ b/examples/plumber/Dockerfile @@ -1,13 +1,14 @@ - FROM rhub/r-minimal -RUN apk add --no-cache --update-cache \ - --repository http://nl.alpinelinux.org/alpine/v3.11/main \ - autoconf=2.69-r2 \ - automake=1.16.1-r0 && \ - # repeat autoconf and automake (under `-t`) - # to (auto)remove them after installation - installr -d \ - -t "libsodium-dev curl-dev linux-headers autoconf automake" \ - -a libsodium \ - plumber +RUN installr -d \ + -t "libsodium-dev curl-dev linux-headers" \ + -a libsodium \ + plumber + +WORKDIR /app + +COPY . . + +EXPOSE 8000 + +ENTRYPOINT ["R", "-e", "pr <- plumber::plumb('plumber.R'); pr$run(host = '0.0.0.0', port = 8000)"] diff --git a/examples/plumber/plumber.R b/examples/plumber/plumber.R new file mode 100644 index 0000000..2f9b1d9 --- /dev/null +++ b/examples/plumber/plumber.R @@ -0,0 +1,10 @@ +#* @get /mean +function(samples = 10) { + data <- rnorm(samples) + mean(data) +} + +#* @post /sum +function(a, b) { + as.numeric(a) + as.numeric(b) +}