Warning: The Collaboratory IAM will be down Tuesday 8th October from 18:00 CET (my timezone) for up to 30 minutes for an update. Please note this will affect all EBRAINS services. Read more.

Warning: The EBRAINS Gitlab will be down Friday 4th October from 18:00 CET (my timezone) until Monday 7th October for a migration effort.



Notebooks can be opened from a link in a collab or other web page.

Some notebooks may need to be passed parameters, e.g. to indicate the context they are run in. For this, you can use the URL query parameters to add environment variables to a Jupyter Notebook.

For example, here is a link to a notebook:

https://lab.ebrains.eu/user-redirect/lab/tree/shared/example_path/notebook.ipynb

Custom environment variables

To add environment variables that are accessible within that notebook (in this case LAB_MY_VARIABLE) use this URL:

https://lab.ebrains.eu/user-redirect/lab/tree/shared/example_path/notebook.ipynb?LAB_MY_VARIABLE=Hello

You can add as many variables as you want but the query string needs to be properly formatted. You can find more info about the query string format here.

Note:

- For the query parameters to be accessible in the notebook they need to be prefixed with LAB_ e.g. LAB_MY_VARIABLE=4 

- For the environment variables to be accessible within the notebook the notebook needs to be accessed via a "shareable link" . You can find a tutorial on how to create a shareable link to a notebook here 

From within a notebook you can then access the environment variable from the notebook as in this code snippet:

import os
os.environ.get('LAB_MY_VARIABLE')

Default environment variables

The following default variables are made available within the notebook:

  • The notebook filename (LAB_NB_NAME)
  • The title of the collab containing the notebook file in its Drive (LAB_COLLAB_TITLE)
  • The Fenix site where the notebook is executed (LAB_EXECUTION_SITE)
  • The Docker image in which the notebook is executed (LAB_IMAGE_NAME)
  • The Docker image version tag (LAB_IMAGE_TAG)
  • The Docker image release date in the format YY.MM (LAB_IMAGE_RELEASE_DATE)

There are other environment variables that will appear only if you access the Lab via a collabs navigation menu (The left hand menu in a collab). It is important to note that these will not be available if you access the Lab in any other way.

  • LAB_COLLAB_ID : the collab id
  • LAB_DOC_PATH : relative path of current XWiki document - This is an empty string for now.
  • LAB_DOC_NAME : XWiki doc name (Lab)
  • LAB_DRIVE_ID : This collab drive id

You can find an example notebook showing how to access the default variables here

Note:

- The environment variables for the notebook filename and the collab containing the notebook are only available in a notebook that was accessed via a shareable link. 

Other environment variables provided by the system

Additionally, the following default system variables are made available within the notebook:

  • The username of the current user (JUPYTERHUB_USER)
Tags:
    
EBRAINS logo