The Jupyter Notebook enables users to create documents that combine live code with narrative text, mathematical equations, visualizations, interactive controls, and other rich output. It also provides building blocks for interactive computing with data: a file browser, terminals, and a text editor. With the recent evolution of Jupyter notebook to Jupyter Lab, this expands most of the existing features which enable you to use text editors, terminals, data file viewers, and other custom components side by side with notebooks in a tabbed work area.

You can access the RCS Jupyter Service at jupyter.rcs.imperial.ac.uk (college network or VPN only).

Load custom Packages/Modules in Jupyter:

Whilst the default kernels available in Jupyter, whether Python or R, offer a certain number of base packages, users normally want to use their own custom packages within their programs. The good news is that Jupyter integrates perfectly with anaconda and its package and environment management systems.

The recommended way to work with python and R packages is via anaconda. This also enables users to create segregated environments for different projects. Get more information on how to use conda environments

Python

Get more information on how to use Python with Anaconda. 

To use custom python modules within a Jupyter lab session:

On login node run:

  • Load module

          module load anaconda3/personal

  • Setup a new conda environment for this project. I named this environment "test1" as an example. * Note that I specify a couple of starting packages to be installed: ipykernel and python with a specific version.

          conda create -n test1 python=2.7 ipykernel

  • Activate the environment:

          source activate test1

  • Install desired packages:

          conda search "package_name"

          conda install package_name[=version]

  • Install python kernel for Jupyter:

          python -m ipykernel install --user --name python2_test1 --display-name "Python2.7 (test1)"

Jupyter:

Spin a new Jupyter Lab session.

Select the new "Python2.7 (test1)" icon in the Jupyter Launcher.

This will enable you to access all python modules in the conda environment created. In this case "test1".

R

Get more information on how to use R with Anaconda

To use custom R libraries within a Jupyter lab session:

On login node run:

  • Load module:

          module load anaconda3/personal

  • Setup a new conda environment for this project. I named this environment "test2" as an example. * Note that I specify a couple of starting packages to be installed: r-irkernel and R with a specific version.

          conda create -n test2 r=3.4.3 r-irkernel

  • Activate the environment:

          source activate test2

  • Install desired packages:

          conda search "package_name"

          conda install package_name[=version]

  • Install R kernel for jupyter:

Run R:

          R

In R run:

          IRkernel::installspec(user = TRUE)

          IRkernel::installspec(name = 'ir343', displayname = 'R 3.4.3 (test2)')

Where "R 3.4.3" is the display name desired to show in the Jupyter launcher.

Jupyter:

Spin a new Jupyter Lab session.

Select the new "R 3.4.3 (test2)" icon in the Jupyter Launcher.

This will enable you to access all R libraries in the conda environment created. In this case "test2" with a custom R version of 3.4.3.