Skip to content

Deploying a RStudio App

Introduction

RStudio (Posit Workbench open-source edition) is a web-based IDE for R development, data analysis, and visualization. Deploying RStudio with a Dockerfile on Klutch.sh provides reproducible environments, managed secrets, and persistent storage—all configured from klutch.sh/app. This guide covers installation, Dockerfile setup, environment variables, storage, Nixpacks overrides, and sample R code to verify your instance.


Prerequisites

  • A Klutch.sh account (sign up)
  • A GitHub repository containing your RStudio Dockerfile (GitHub is the only supported git source)
  • Optional: external databases or storage your R workflows will query

For onboarding, see the Quick Start.


Architecture and ports

  • RStudio Server serves HTTP on internal port 8787. Choose HTTP traffic in Klutch.sh and set the internal port to 8787.
  • Persistent storage is recommended for user home directories and projects.

Repository layout

rstudio/
├── Dockerfile # Must be at repo root for auto-detection
└── README.md

Keep secrets out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Build and run locally:

Terminal window
docker build -t rstudio-local .
docker run -p 8787:8787 \
-e PASSWORD=changeme \
-e USER=rstudio \
rstudio-local

Dockerfile for RStudio (production-ready)

Place this at the repo root; Klutch.sh auto-detects Dockerfiles.

FROM rocker/rstudio:latest
ENV USER=rstudio
ENV PASSWORD=changeme
ENV PORT=8787
EXPOSE 8787
CMD ["/init"]

Notes:

  • Pin to a specific tag (e.g., rocker/rstudio:4.3.1) for stability.
  • /init starts the RStudio Server on port 8787 inside the container.

Environment variables (Klutch.sh)

Set these before deploying:

  • PORT=8787
  • USER=rstudio
  • PASSWORD=<secure-password>
  • Optional: ROOT=TRUE if you need root privileges within the container (use cautiously)

If deploying without the Dockerfile and relying on Nixpacks:

  • NIXPACKS_START_CMD=/init

Attach persistent volumes

Add storage in Klutch.sh (path and size only):

  • /home/rstudio — user projects and libraries.
  • /var/lib/rstudio — server state (optional).

Ensure paths are writable inside the container.


Deploy RStudio on Klutch.sh (Dockerfile workflow)

  1. Push your repository—with the Dockerfile at the root—to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  3. Select HTTP traffic and set the internal port to 8787.
  4. Add environment variables (user, password, and optional root flag).
  5. Attach volumes at /home/rstudio (and /var/lib/rstudio if desired) sized for your projects.
  6. Deploy. Access RStudio at https://example-app.klutch.sh and log in with the configured user/password.

Sample R code to verify

Create a quick plot via the console:

x <- rnorm(1000)
png("/home/rstudio/plot.png")
hist(x, breaks = 30, col = "skyblue", main = "RStudio on Klutch.sh")
dev.off()

Health checks and production tips

  • Add an HTTP readiness probe to / (login page) to ensure the server is responding.
  • Keep credentials in Klutch.sh secrets; rotate passwords regularly.
  • Pin image versions and test upgrades in staging before production.
  • Monitor storage usage on /home/rstudio; resize volumes as projects grow.

RStudio on Klutch.sh delivers reproducible Docker builds, managed secrets, and persistent workspaces—without extra YAML or CI steps. Configure ports, credentials, and storage, then start analyzing data in your browser.