0Pricing
R Academy · Lesson

Deploying Plumber APIs to Production

Containerize and deploy Plumber APIs with Docker and cloud platforms.

Production Deployment Options

A Plumber API can be deployed in several ways:

  • Docker container — portable, reproducible, works anywhere
  • Posit Connect — push-button deploy with scheduling
  • Digital Ocean / EC2 — a plain Linux VM running R

Docker is the most portable option and the industry standard for production R APIs.

Plumber API Entry Point

Create a top-level api.R that starts the Plumber server. Use Sys.getenv('PORT', unset='8000') so the port can be set by the container orchestrator without changing code.

# api.R
# library(plumber)
#
# pr <- plumb('routes.R')
# port <- as.integer(Sys.getenv('PORT', unset = '8000'))
# pr$run(host = '0.0.0.0', port = port)
#
# Listening on 0.0.0.0 is required inside Docker
# (127.0.0.1 is only reachable inside the container)

All lessons in this course

  1. Introduction to Plumber and REST
  2. Creating GET and POST Endpoints
  3. Authentication and API Security
  4. Deploying Plumber APIs to Production
← Back to R Academy