Skip to content

Instantly share code, notes, and snippets.

@fauxneticien
Last active February 11, 2021 20:01
Show Gist options
  • Save fauxneticien/6a37e2f6ea34768de234a134532e26e5 to your computer and use it in GitHub Desktop.
Save fauxneticien/6a37e2f6ea34768de234a134532e26e5 to your computer and use it in GitHub Desktop.
ubuntu-web-rstudio_sept2020

Launch RStudio server on Ubuntu 20.04

1. Launch server (DigitalOcean, Packet, etc.) with Ubuntu 20.04 and get IP XXX.XXX.XXX.XXX

Test that logging in works

ssh [email protected]

Copy files you want to work onto server

  • Note you're not SSH-ed in so file path is relative to your local directories
  • Note -r is recursive, assuming copying relevant folder(s) and files within
scp -r /path/to/local/dir [email protected]:/path/on/remote/server

2. Install Docker

Taken from: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04

sudo apt update

sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

sudo apt update

apt-cache policy docker-ce

sudo apt-get -y install docker-ce

sudo systemctl status docker

3. Launch RStudio

Notes:

  • -rm flag will delete container when it's done
  • -d flag runs in background/detached mode
  • -v maps your files on the server into the folder /path/within/container within the Docker container (so you can use setwd() within the container to navigate to this location to use the files)
  • -p maps the server port 80 (default web) to the port 8787 in the container (RStudio Server by default runs out of 8787), so you can go to your IP XXX.XXX.XXX.XXX (=XXX.XXX.XXX.XXX:80) to access the web interface
  • -e you must obligatorily set a password for the web interface (default usename is 'rstudio', default password used to be 'rstudio' as well)
  • The container image rocker/tidyverse will automatically be pulled from DockerHub since you're on a fresh install of Ubuntu.
docker run --rm -d -v /path/on/remote/server:/path/within/container -p 80:8787 -e PASSWORD=rstudio rocker/tidyverse
docker run --rm -d -v /home:/home/rstudio -p 80:8787 -e PASSWORD=rstudio --name rstudio rocker/tidyverse
docker exec rstudio bash -c 'chown rstudio /home/rstudio'

4. Log into RStudio web interface at XXX.XXX.XXX.XXX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment