Skip to content

Running RStudio on CREATE

In order to run RStudio from the HPC nodes it is necessary to request a batch job and then create a tunnel to the running process.

Tip

For a complete guide on how to submit batch jobs on CREATE HPC, then please refer to our guide document here.

Create a script to be submitted using sbatch

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash -l

#SBATCH --job-name=ops-rstudio
#SBATCH --partition=cpu
#SBATCH --ntasks=1
#SBATCH --mem=2G
#SBATCH --signal=USR2
#SBATCH --cpus-per-task=1

module load rstudio/v2023.03.0_386-gcc-13.2.0-r-4.3.0-python-3.11.6

# get unused socket per https://unix.stackexchange.com/a/132524
export PASSWORD=$(openssl rand -base64 15)
readonly IPADDRESS=$(hostname -I | tr ' ' '\n' | grep '10.211.4.')
readonly PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
cat 1>&2 <<END
1. SSH tunnel from your workstation using the following command:

      Linux and MacOS:
      ssh -NL 8787:${HOSTNAME}:${PORT} ${USER}@hpc.create.kcl.ac.uk

      Windows:
      ssh -m hmac-sha2-512 -NL 8787:${HOSTNAME}:${PORT} ${USER}@hpc.create.kcl.ac.uk

      and point your web browser to http://localhost:8787

2. Login to RStudio Server using the following credentials:

      user: ${USER}
      password: ${PASSWORD}

When done using the RStudio Server, terminate the job by:

1. Exit the RStudio Session ("power" button in the top right corner of the RStudio window)
2. Issue the following command on the login node:

      scancel -f ${SLURM_JOB_ID}

END

# Create custom database config
DBCONF=$TMPDIR/database.conf
if [ ! -e $DBCONF ]
then
printf "\nNOTE: creating $DBCONF database config file.\n\n"
echo "directory=$TMPDIR/var-rstudio-server" > $DBCONF
fi

rserver --server-user ${USER} --www-port ${PORT} --server-data-dir $TMPDIR/data-rstudio-server \
--secure-cookie-key-file $TMPDIR/data-rstudio-server/secure-cookie-key \
--database-config-file=$DBCONF --auth-none=0 \
--auth-pam-helper-path=pam-env-helper

printf 'RStudio Server exited' 1>&2

Submit the script

1
k1234567@erc-hpc-login1:/scratch/users/k1234567$ sbatch ops-rstudio.sh

Connect to RStudio server using the output file details

Once the job has started an output file will be generated that will have the details and user credentials required for you to be able to login and connect.

Using Singularity containers

This guide provides step-by-step instructions for setting up and running RStudio Server within a Singularity container on the CREATE HPC system.

Info

For an introductory setup on how to get started with Singularity on CREATE HPC, refer to our guides here.

Take note

Singularity is only accessible from the compute nodes, to use Singularity and avoid the memory limitations of the login nodes, please request an interactive session.

Setting up the container

You must first pull your required container image from DockerHub:

Info

To load a specific version of RStudio, check the Tags section on DockerHub to find the version you need

1
singularity pull docker://rocker/rstudio:4.4.3

This will create a Singularity image file called: rstudio_4.4.3.sif.

Creating the batch script

Tip

Refer to our guide documentation here on how to bind the non-default personal library locations, that you have created for R on the CREATE HPC host, to your container.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash -l

#SBATCH --job-name=ops-rstudio
#SBATCH --partition=cpu
#SBATCH --ntasks=1
#SBATCH --mem=2G
#SBATCH --signal=USR2
#SBATCH --cpus-per-task=1

module load python/3.11.6-gcc-13.2.0
CONTAINER_PATH="./rstudio_4.4.3.sif"

export PASSWORD=$(openssl rand -base64 15)
readonly IPADDRESS=$(hostname -I | tr ' ' '\n' | grep '10.211.4.')
readonly PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')

cat 1>&2 <<END
1. SSH tunnel from your workstation using the following command:

      Linux and MacOS:
      ssh -NL 8787:${HOSTNAME}:${PORT} ${USER}@hpc.create.kcl.ac.uk

      Windows:
      ssh -m hmac-sha2-512 -NL 8787:${HOSTNAME}:${PORT} ${USER}@hpc.create.kcl.ac.uk

      and point your web browser to http://localhost:8787

2. Login to RStudio Server using the following credentials:

      user: ${USER}
      password: ${PASSWORD}

When done using the RStudio Server, terminate the job by:

1. Exit the RStudio Session ("power" button in the top right corner of the RStudio window)
2. Issue the following command on the login node:

      scancel -f ${SLURM_JOB_ID}

END

DBCONF=$TMPDIR/database.conf
if [ ! -e $DBCONF ]
then
    printf "\nNOTE: creating $DBCONF database config file.\n\n"
    echo "directory=$TMPDIR/var-rstudio-server" > $DBCONF
fi

singularity exec \
    ${CONTAINER_PATH} \
    /usr/lib/rstudio-server/bin/rserver --server-user ${USER} --www-port ${PORT} \
    --auth-none=0 \
    --auth-pam-helper-path=pam-helper \
    --server-data-dir $TMPDIR/data-rstudio-server \
    --secure-cookie-key-file $TMPDIR/data-rstudio-server/secure-cookie-key \
    --database-config-file=$DBCONF

printf 'RStudio Server exited' 1>&2

Once you have submitted the script through sbatch, the slurm output file will have all of the information needed to launch RStudio through Singularity.