Tutorial

Last modified by chaney08 on 2021/07/20 19:20

Purpose

The purpose of the Lab tutorial is to teach you how to create and use your first notebook as well as to explain the basic principles to allow you to continue beyond the scope of the tutorial in developing your own notebooks.

How to get to the Lab

To get to the Lab, simply go to a Collab that you are a member of and where you want to work and click on the "Lab" navigation element in the left pane, as shown in the following screenshot:

1622123755771-230.png

Note: the "The Collaboratory" collab is visible to you because it is public but you are likely not a member so you won't see a Lab navigation element in that collab.

How to create a notebook

Upon entering the Lab, you see menus across the top, and tabs down the left edge. The top-most tab on the left edge (folder icon) displays the content of the selected folder in the Collaboratory.Drive. The default folder is the top folder of the Drive of the collab from where you opened the Lab. Among the files visible in this folder tab, you might have existing notebook files (the ones with the *.ipynb extension). You can open and run these notebooks. You can only save edits and/or the log of your own execution output if you have write permission in that collab. Or you can save the notebook to another collab's Drive from the top menu with File > Save As.

On the right-hand side, you will see your "Launcher;" this is where you can create a new notebook.

 1622125349931-642.png

If you click on the "Python 3" button underneath the "Notebook" heading, it will create a new notebook called "Untitled" in the folder pane and open it as a new tab in the right-hand pane. You can give this notebook an appropriate name by right-clicking on the file in the folder pane and clicking "Rename." It will also change the file name in the right-hand notebook viewer.

Clicking the tabs along the left edge will minimize the left-hand pane.

How to develop/run a notebook

Notebooks support the Python 3 programming language and other languages may be added in the future. For now, any code you type into these notebooks should be in the Python 3 syntax. Notebooks are divided into "Cells". You can execute the code in each cell, one cell after another, or sequentially. All cells in a notebook share the same environment; therefore importing a Python package/library in one cell will allow it to be used in another cell. Variables set in one cell are accessible in other cells. Cells help organise your code. An example of this can be seen below. 

1622127087243-656.png

In the above example, you see a red highlight and a green highlight. The red highlight shows the button you press to add a new cell to the notebook. The green highlight shows the button you press to run the selected cell. The selected cell is shown by a blue bar to the left of the cells. In the above image, you can see that the third cell is currently selected. This process allows you to develop a full program using Python with your notebooks.

The results of executing each cell are shown in the white space between cells. These results are stored in the ipynb file for the next time you open the notebook.

Sharing a link to your notebook

Sharing a link to your notebook is as simple as right-clicking on the file you want to share (in the folder tab) and choosing "Copy Shareable Link" from the context menu. The URL is copied to your browser's copy/paste buffer. You can send the link to anyone you want to view the notebook; the users will need to have read access to the corresponding collab. You can also use this link to create navigation elements inside collabs that will link directly this notebook.

1622128734293-231.png

Calling the Drive from a notebook

To see how to retrieve and edit files from the Drive, please have a look at our notebook which you can access by following this link: https://lab.ebrains.eu/user-redirect/lab/tree/shared/The%20Collaboratory/Tutorial/Drive_Mounted_fileSystem.ipynb

Calling the Bucket from a notebook

You can find an example on how to call the Bucket storage from a notebook using the following notebook: https://lab.ebrains.eu/user-redirect/lab/tree/shared/Data%20Proxy/Example%20Buckets%20Programmatic.ipynb

Conclusion

Now that you have finished this tutorial, you know the fundamentals to using the Lab, and you can now develop your own notebooks going forward.