MARK
MARK

Reputation: 2362

Starting jupyter notebook programmatically from another notebook

Is it possible to start another notebook from the current notebook? I know how to create and save the current notebook but I cannot launch another notebook from the current one. %run does not work while starting another notebook

Upvotes: 5

Views: 2488

Answers (3)

BBFlyer
BBFlyer

Reputation: 1

If you are running Jupyter Notebook server, you can copy the URL of an open Notebook and paste it into a HTML hyperlink in a different notebook's markdown cell.

For example, in a markdown cell put <a href="http://localhost:8888/notebooks/examples/Backup.ipynb">bakup</a>. Run the cell. Click on the hyperlink and the linked notebook will open in a new tab. This has been tested on Windows 11 with the Edge browser.

I have not been able to accomplish this with Jupyter Lab, yet.

Upvotes: 0

Aristide
Aristide

Reputation: 3994

The answer of kikocorreoso should open the specified notebook at launch. When this is not required or desirable, you can simply create a clickable link (even relative) in a Markdown cell, i.e.:

Click to open your [notebook](../others/name_of_the_notebook.ipynb).

Upvotes: 2

kikocorreoso
kikocorreoso

Reputation: 4219

If I suppose you know the url for the notebook you want to open you could open it in the following way:

This code should be a code cell in your notebook:

%%javascript
window.open('http://localhost:8888/notebooks/Name_of_the_notebook.ipynb')

If you don't know the complete path (url) to the notebook you should, at least, know the name of the notebook you created. In this case you could do:

%%javascript
var name_of_the_notebook = 'Name_of_the_notebook.ipynb'
var url = window.location.href.split('/')
var newurl = url[0] + '//'
for (var i = 1; i < url.length - 1; i++) {
    console.log(url[i], newurl)
    newurl += url[i] + '/'
}
newurl += name_of_the_notebook
window.open(newurl)

Maybe the browser will ask if you want to open the new tab.

Upvotes: 7

Related Questions