How to install RStudio Server in Databricks

To install RStudio Server in Databricks you need to download RStudio, install it and setup it up inside Databricks notebook and settings.

  1. Create a new notebook file

2. Copy, paste and run. This will create a script rstudio-install.sh which will download the RStudio Server installer.

script = """#!/bin/bash

set -euxo pipefail
RSTUDIO_BIN="/usr/sbin/rstudio-server"

if [[ ! -f "$RSTUDIO_BIN" && $DB_IS_DRIVER = "TRUE" ]]; then
  apt-get update
  apt-get install -y gdebi-core
  cd /tmp
  # You can find new releases at https://rstudio.com/products/rstudio/download-server/debian-ubuntu/.
  wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-2022.02.1-461-amd64.deb -O rstudio-server.deb
  sudo gdebi -n rstudio-server.deb
  rstudio-server restart || true
fi
"""

dbutils.fs.mkdirs("/databricks/rstudio")
dbutils.fs.put("/databricks/rstudio/rstudio-install.sh", script, True)

3. In your second Cmd run the shell file

%fs head /databricks/rstudio/rstudio-install.sh

4. Now go to Compute -> Configuration select your clusters (if you don’t have one, then create one). In Advanced options select “Init Scripts” and add the shell file

dbfs:/databricks/rstudio/rstudio-install.sh

5. Confirm and restart your cluster

6. When the cluster is up again select the Cluster -> Apps menu in the top. And press the Set up RStudio

7. Press Open RStudio and login with your credentials

Now you have a full functional running RStudio inside your Databricks.

Databricks source documentation: https://docs.databricks.com/sparkr/rstudio.html#install-rstudio-server-open-source-edition