Proof of concept for dockerising an R Plumber API for the DfE's data screener.
- Download R binary (https://www.stats.bris.ac.uk/R/)
- Download the R Extension for VS Code, you may be prompted to download the
languageservice
to use R code locally. Alternatively you can use an R-specific IDE such as RStudio - Open
server.R
click the Run button at the top of the file. Alternatively, open an R Terminal and use the commandsource("server.R")
- Open up Postman/PowerShell/curl etc. to hit the endpoints:
GET localhost:8000/screen
POST localhost:8000/screen
The GET endpoint is just to confirm the API is running.
For the POST endpoint,
dataFile
andmetaFile
arguments should be submitted with aform-data
request body. Example files can be found in the "example-data" folder
The API can also be run in a Docker container. Open up a terminal in the root of the project, and create an image using
docker build -t eesyscreener .
then run it using
docker run --rm --name eesyscreener -p 8000:8000 eesyscreener
You may need to enter pak::lockfile_install
to install the dependencies locally before running the API.
If any additional dependencies are added, run the following command to update the lockfile before commiting changes.
pak::lockfile_create(pkg = c("plumber", "github::dfe-analytical-services/eesyscreener", "readr", "<additional dependency 1>", "<additional dependency 2>"))
If the data and meta files supplied to the POST endpoint generate an error from eesyscreener
, and you only want to generate a successful response for testing, replace the function call in screen_Controller.R
:
result <- screen_files(req$body$dataFile$filename, req$body$metaFile$filename, req$body$dataFile, req$body$metaFile)
with
write.csv(example_data, "example_data.csv", row.names = FALSE)
write.csv(example_data.meta, "example_data.meta.csv", row.names = FALSE)
result <- screen_files("example_data.csv", "example_data.meta.csv", example_data, example_data.meta)