Running JupyterLab at HPC2N - R

Running JupyterLab at HPC2N - R

For how to use Jupyter notebook in general, see the Using Jupyter at HPC2N page.

1) In order to use R kernels in a Jupyter notebook you need to install a suitable kernel, for instance the IRkernel. First load the modules for JupyterLab and a compatible R version with the same tool chain, at this moment the following combo works:

module load GCC/12.3.0 R/4.3.2 
module load OpenMPI/4.1.5 JupyterLab/4.0.5

2) Then, start an R session on the command line and install the IRkernel (choose a location CRAN, for instance Sweden):

#give a name to the kernel in this case I chose ir432
IRkernel::installspec(name = 'ir432', displayname = 'R 4.3.2')

3) Once this package is installed, write a submit file to start a JupyterLab (in batch mode) using this template: 

Example, loading JupyterLab/4.0.5, its prerequisites, and the R version 4.3.2 :

# Here you should put your own project id
# This example use 1 core
#SBATCH -n 1
# Ask for a suitable amount of time. Remember, this is the time the Jupyter notebook will be available! HHH:MM:SS.
#SBATCH --time=05:00:00

# Clear the environment from any previously loaded modules
module purge > /dev/null 2>&1

# Load the modules for the R and JupyterLab
module load GCC/12.3.0 R/4.3.2 
module load OpenMPI/4.1.5 JupyterLab/4.0.5

# Start JupyterLab with the installed kernel
jupyter lab --no-browser --ip $(hostname)


See here for an explanation of the options to jupyter.

4) Submit the above submit file (here I named it


You get the <job-id> when you do the above command.

Check the SLURM output file (slurm-<>.out); grab the URL with the hostname as described in the first part of this document, since the localhost one requires you to login to the compute node.

5) Start a webbrowser within HPC2N (ThinLinc interface). Put in the URL you grabbed, including the token.

6) Inside JupyterLab, start the new R kernel. Just click the launcher for that one if no other kernel is running. 

If a kernel is running (shown under kernels), then shut down that kernel and click "Kernel" in the menu, and then "Change kernel". Pick your kernel from the drop-down menu.

7) You can now run your files etc. with the R kernel.

NOTE! Sometimes it is still running on the default kernel. If so, Click the 3 little dots in the right side of the editor-window for the program and pick your kernel. Then rerun your files.

Updated: 2024-04-11, 12:28