Using the plumber package to expose services on the Azure DSVM

by Andrie de Vries

The plumber package is an “An API Generator for R”, written by Jeff Allen. The package makes it possible to turn any R script into a web service, and you can then call this web service from any language that can make REST calls.

The Azure Data Science Virtual Machine (DSVM) is a hosted virtual machine with pre-installed data science utilities.

Usually it is very easy to deploy your plumber APIs, but my first attempt at doing this on the Azure DSVM failed.

After some experimentation, I discovered that you must do:

  • Assign a port that is not in use. The default is port 8000, but this is already used by Jupyter Hub. Try port 8888, for example.
  • Listen on all ports (host = "0.0.0.0"). The default is to listen only on localhost.
  • Remember to open the port 8888 in the Azure portal.

This code works for me:

library(plumber)
r <- plumb("plumber/test-plumber.R")
r$run(port = 8888, host = "0.0.0.0")

To enable this as a service on the Azure DSVM, use the instructions for hosting using Docker or pm2.

Share Comments ·

You may leave a comment below or discuss the post in the forum community.rstudio.com.