Links between IPython notebooks

PythonIpython

Python Problem Overview


Is it possible to link one IPython notebook to another with a hyperlink in a Markdown cell? If I try

Link to [Notebook 2](files/notebook2.ipynb)

or

Link to <a href="files/notebook2.ipynb">Notebook 2</a>

A new tab is opened with raw unformatted contents of the ipynb file. Is there a way to get IPython to open another notebook for use in a new tab via a hyperlink?

Python Solutions


Solution 1 - Python

Since IPython 2 you may use exactly the syntax you first tried:

Link to [Notebook 2](notebook2.ipynb)

Solution 2 - Python

It is now possible to do this with Ipython 1.0+ at least.

Just do: localhost:8888/My Notebook.ipynb

Here is the documentation for this feature. https://github.com/ipython/ipython/pull/3058

Solution 3 - Python

From http://python.6.n6.nabble.com/where-is-the-code-to-generate-IPython-Notebook-URL-for-a-new-ipynb-file-td4996991.html:

You can access a json version of all the notebooks from url: $host/notebooks

Here is a snippet that worked for me:

    import urllib2
    import json
    data = urllib2.urlopen("http://127.0.0.1:8888/notebooks")
    json_data=data.read()
    list_o_dicts=json.loads(json_data)
    for d in list_o_dicts:
        if d['name'] == 'test':
            print d['notebook_id']

Modify this according to your need.

** on further reading, I just realized OP was also seeking new notebook creation, keeping my answer anyway as way to work with linking existing notebooks.

One way to try for OP's goal is to run a script which will create a new notebook.ipynb file into the ipython folder where ipython notebook was started from. That .ipynb file can be templated from a new ipython notebook created from dashboard, with the name and id of the notebook replaced with whatever you are trying to link from your existing notebook. I have not tried this, but should work since dropping a .ipynb extension file into ipython folder does show it up in the dashboard.

Solution 4 - Python

In addition to akim's suggestion - you can link to any (py or ipynb) file using a relative link, starting with "edit", and and then from the directory where you started the server.

E.g. in a markdown cell, if I want to reference a file whose relative location (relative to my git repo, which is also where I launched the notebook server) is "./path/to/source.py", I'd add:

[link to source](/edit/path/to/source.py)

Solution 5 - Python

Remember that if your file name has spaces you will need to replace those with %20

eg:

[Numpy](Numpy%20For%20Python.ipynb)

Solution 6 - Python

Unfortunately, this is not practically possible. The link would need to be to the notebook ID (e.g. /a1e2a88f-3b91-4a4e-8ca1-d4fd7240f750 for the one I'm working on right now). This is an UUID created at startup by the IPython server. So you can copy the link from IPython Dashboard, but it will be valid only until you restart.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMikeView Question on Stackoverflow
Solution 1 - PythonakimView Answer on Stackoverflow
Solution 2 - PythonDavidAView Answer on Stackoverflow
Solution 3 - Pythonnom-mon-irView Answer on Stackoverflow
Solution 4 - PythonPeterView Answer on Stackoverflow
Solution 5 - PythonNick LeechView Answer on Stackoverflow
Solution 6 - PythonlRemView Answer on Stackoverflow