Open specific Jupyter .ipynb when launching interactive app

Hello all,

We’re trying to setup a jupyter notebook guide to help people learn how to use them. We have an interactive app setup for jupyter notebook that works great. We’re just trying to add the simple addition of opening a specific notebook when the app is launched instead of the user seeing a directory.

Currently in our script.sh.erb we’re running jupyter notebook guide.ipynb --config=config.py. If I run this locally, it starts a jupyter notebook as intended and opens up guide.ipynb. However when I do that from ondemand, it opens up the directory that guide.ipynb exists in and stops there.

I’ve gone through the documentation for jupyter notebook’s config options and tested a few things, none of which open the specific notebook, or they prevent me from connecting to the jupyter app at all because I changed the URL to something that I shouldn’t have.

I just wanted to ask the community to see if anyone else had gotten something like this to work.

You can use the next=otherurl query parameter to the login page. That’ll redirect jupyter after you login. We do something similar to step into a specific directory.

If this is an entirely separate jupyter app then you can just hard code the .ipynb file there.

If it’s for say you’re production app where you want to give folks a checkbox toggle to do this, open to a specific file, OR just open to your home it’d be a little more complicated, but it’s basically the same scheme we do with jupyter_api. We have a checkbox to work in a class room environment and if it’s checked, we set the jupyter_api environment variable in the before.sh.erb and pass it back to the UI through conn_params in the submit.yml.erb.

Thanks for the information! I copied those lines from your link into my view.html.erb, and then hard coded the .ipynb.

<%-
  base_url  = "/node/#{host}/#{port}"
  login_url = "#{base_url}/login"
  #next_url  = "#{base_url}/#{jupyter_api}"
  next_url  = "#{base_url}/notebooks/ondemand/test1.ipynb"

  full_url="#{login_url}?next=#{URI.encode(next_url)}"
  form_id = "juypyter_form#{login_url.gsub('/', '_')}"
%>

I tried a few other things for the next_url as well, such as next_url=test1.ipynb and next_url = "#{base_url}/test1.ipynb", but I continued to land in the directory. I must have missed something.

/notebooks/ondemand/test1.ipynb is the full path minus login_url when I actually click on the specific jupyter notebook in my browser.

ipynb path - https://<hostname>/node/<server name>/14427/notebooks/ondemand/test1.ipynb

jupyter directory that I land in path - https://<hostname>/node/<server name>/14427/tree/ondemand/

First, I’d be sure you’re actually using full_url in the action element of the form.

If you are, then you may need a version upgrade for the login API to accept a next query parameter. That could have been added at some point, though I’m not sure without looking into it deeper.

I will say that I actually verified you would do this, I checked it myself, so I’m sure you can on a recent version of Jupyter (2.1.4).

Yup that was it. I was using a slightly older jupyter notebook app. Updated it to be the most recent and it works like a charm! Thanks for the help!