Deploying a Minimal API using plumber on DigitalOcean
Some quick notes on deploying an API (generated with plumber) on DigitalOcean.
On your local machine install a couple of packages from GitHub.
In RStudio open a new script and create a single, simple API endpoint which will return today’s date. Create a new folder (I’ll call mine
api) and save the script in that folder as
Then in the RStudio console, start the API on port 8000.
You should then be able to access two endpoints via your browser:
http://127.0.0.1:8000/__swagger__/: the Swagger interface for your API and
http://127.0.0.1:8000/date: the date endpoint defined above.
In the image below you’ll see the result returned from a GET request to that endpoint.
If you have the above working then all of the local development is done. It’s time to deploy.
Creat an account on DigitalOcean.
Provision a Test Droplet
The process of setting up a Droplet on DigitalOcean is made very simple with some functionality from
This will do a number of things:
- authenticate a connection between R and DigitalOcean;
- create an instance (or “Droplet”) on DigitalOcean;
- create a swap file;
- install a recent version of R;
- install the
- configure the NGINX web server to route traffic from port 80 to your API;
- configure a firewall to only allow connections on ports 22 (SSH) and 80 (HTTP).
This will take a few minutes. Be patient.
Once it’s done, check your dashboard on DigitalOcean to confirm that a new instance has been created (it will have a
plumber tag). Grab the associated IP address and open it in your browser. You should see the message “plumber is alive”, generated by the default (placeholder) API.
You can destroy this instance now from the dashboard. We just wanted to check that everything works.
Provision a Production Droplet
Now we are going to create another instance, but this time without the example API.
Here we see another way to get information on your instances using
Deploy to a Production Droplet
It’s now a simple matter to deploy our date API to this instance.
If you make changes to the code for the API they can be redeployed by simply running
Decomissioning a Droplet
Your instance on DigitalOcean is charged by the hour. When you are done it makes sense to destroy the instanc. This is easily done via the dashboard.