Adding a notebook as a navigation element/embedding into a wiki page

Version 2.1 by chaney08 on 2021/06/04 13:54

This page describes multiple ways of referring to a Jupyter Notebook from an element in the navigation panel of a collab in Wiki to open a Jupyter Notebook in the collab window.

Link to the Lab

The Lab link in each collab opens JupyterLab with its file browser focused on that collab's Drive. This does not open a specific Notebook in JupyterLab; it is up to the user to select a Notebook file from that folder.

Example for a collab called my-collab-name:

URL: https://wiki.ebrains.eu/bin/view/Collabs/my-collab-name/Lab

Link to a Jupyter Notebook

Users can add a navigation element for a collab that will open a specific Jupyter Notebook in that collab. To do so, you first have to determine the URL of the Jupyter Notebook and then add a link to an iFrame in the collab's navigation.

Getting the relevant URL

  1. Open the Lab
  2. In the file browser of JupyterLab, browse to the Notebook file, right-click on the Notebook file and select Copy Shareable Link. You now have the URL you need.

Creating the navigation element

Now that you have the URL you need, to create a navigation element linking to the Notebook just go to the collab you want to add the navigation element.

To add a Top-level navigation element you need to go to the main page of a the collab in question and click "Create". See the following image for an example: 1619614141909-944.png

If you cannot see the "Create" button, you do not have the appropriate rights for this collab and you need to talk to the collab admin about getting those rights. 

Otherwise, if you click on create you will be met by a new "Create Page" screen, you need to fill out the title and when done, it is important you click on "Integrate external page with an iFrame" option, as in the following image:

1619614348194-886.png

When you click on the green "Create" button, you will be brought to a page that will ask you to enter in a URL (You can also change the title in this page). Use the URL you retrieved in  the "Getting the Relevant URL" section. Once you click create, you will have your new navigation element created.  1619614515992-874.png

This link will bring you straight to the relevant notebook. 

If you want a Sub-menu navigation element, the only difference is where you select the initial "Create" button.  Using the same collab, if I clicked on the "Expandable selection" wiki page, I have the option to click "Create" as seen in the following image: 1619614700438-489.png

If I click on the "Create" in the above image and follow the exact same process as detailed above, I will end up with the same link as a submenu instead of a top level navigation element. In the above image you can see "SubLinkDemo" under "Expandable selection". This functions exactly the same as the "Test link to my test Notebook" link we created earlier, except as a sub menu.

Example for a collab named Demo collab:

Shareable link: https://lab.ebrains.eu/user/alice/lab/tree/shared/Demo%20collab/demo1.ipynb

Final URL: https://lab.ebrains.eu/user-redirect/lab/tree/shared/Demo%20collab/demo1.ipynb

Embed a notebook viewer in a wiki page

  1. Export a snapshot of a notebook as an HTML file
    1. Open the Lab, choose a notebook, optionally run it, and then export the notebook as HTML.
    2. lab_export_html.png

  2. Upload the HTML file as an attachment to a wiki page
    1. Go to the wiki page where to embed the notebook viewer. Before editing the wiki page, attach the HTML file generated above in the Attachments section at the bottom of the wiki page. Upload the HTML file. Remember the HTML filename as you will need it for the next step.
       
    2. upload_notebookviewer.png

  3. Insert a "Jupyter Notebook Viewer" macro in a wiki page
    1. Edit your wiki page (the one with the HTML attachment). Select a place in the wiki page where to add the notebook viewer. Click the cog icon to add a macro and select the "Jupyter Notebook Viewer" macro from the macro select dialog and click select.
    2. In the "Filename" field, enter the name of the HTML file you have uploaded in the previous step. In our example this is "hello_collab.html". Under revision, enter the revision of the attachment you want to use. In most cases using the default value will be ok. The revision number is the number that appears on the right of the uploaded filename in the attachment section. In our example above, the revision was the default 1.1 (see figure above).
    3. In the "Height" field, specify the container height in pixels. Default is 500. If content overflows, the browser will display a vertical scrollbar.
    4. Click the submit button.
    5. jupyter_nbviewer_macro.png

    6. Save and view the wiki page. You should now see the saved snapshot of your notebook in your wiki page.