Jupyter Notebook

This section provides a brief introduction to using Jupyter notebooks via the Web UI or remotely (accessing the notbook server running local inside a docker container) in VSCodium.

Using the Web UI

The Jupyter Notebook Web UI can be accessed with any web browser (Chromium, Firefox, ...) at the following URL:127.0.0.1:8888

NOTE: Here all files are listed, which are located in the folder workspace (empty at the first start).

Jupyter-Notebook start page
Start page of the Jupyter Notebook WebUI

Export a Jupyter Notebook (PDF)

A Jupyter Notebook can be exported as a PDF file under File -> Download as -> PDF via LaTeX (.pdf):

Jupyter-Notebook start page
PDF export with the nbconvert extension

Using VSCodium

First install the Jupyter Extension from ms-toolsai:

Screenshot VSCodium Jupyter Extension
VSCodium Jupyter (ms-toolsai) Extension

Then open the corresponding notebook file (.ipynb) with VSCodium. To connect to the remote notebook server open the Command Palette (by pressing STRG+Shift+P), start typing Jupyter and select Jupyter: Specify Jupyter Server for Connections:

Screenshot VSCodium Jupyter Extension Specify Jupyter Server for Connections
VSCodium command palette, Specify Jupyter Server for Connections

Afterwards choose Existing:

Screenshot VSCodium Jupyter Extension Specify Jupyter Server for Connections, pick how to connect to Jupyter, choose existing
VSCodium Specify Jupyter Server for Connections, pick how to connect to Jupyter

Enter the following URI and press enter: http://127.0.0.1:8888/?token=None:

Screenshot VSCodium Jupyter Extension Specify Jupyter Server for Connections, enter the URI
VSCodium Specify Jupyter Server for Connections, enter the URI of the running Jupyter server

Now you can run the notebook cells remotely with our Docker environment :)

Once you have set the remote URI, the next time you open a notebook file you can simply select the server by clicking Jupyter Server: Remote in the lower right corner of the VSCodium window:

Screenshot Jupyter Server: Remote icon
VSCodium Jupyter Server: Remote icon

And choose the last used connection:

Screenshot Jupyter Server: Remote icon, choose last used connection
VSCodium Specify Jupyter Server for Connections, pick last used connection

Export a Jupyter Notebook (PDF)

To export the notebook as a PDF file you can use the following code cell (does not work with the WEB UI!):

import os, IPython, subprocess
nbpath = os.path.join(
    "/home/pyspark-client/workspace", 
    IPython.extract_module_locals()[1]["__vsc_ipynb_file__"]
    .split("/workspace/")[1])
cmd = "jupyter nbconvert --to pdf --Exporter.preprocessors nbconvert.preprocessors.ExtractAttachmentsPreprocessor --template /home/pyspark-client/nbconvert-templates/fernuni-latex "+nbpath
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
output, error = p.communicate()

Screenshot code cell to export as pdf
VSCodium notebook code cell to export as PDF

Alternatively you can use the following bash cell which also works with the WEB UI (you have to manually set the path to the notebook file):

!jupyter nbconvert --to pdf --template \
'/home/pyspark-client/nbconvert-templates/fernuni-latex' \
--Exporter.preprocessors nbconvert.preprocessors.ExtractAttachmentsPreprocessor \
~/workspace/PATH/TO/FILE.ipynb

NOTE: You can ignore the WARNING and CRITICAL messages from inkscape regarding dbus. Dbus is mostly a messaging system for things like notifications. The errors probably only mean it can't find dbus running, which shouldn't hurt anything.