# Open specific Jupyter .ipynb when launching interactive app

**URL:** <https://discourse.openondemand.org/t/open-specific-jupyter-ipynb-when-launching-interactive-app/1225>\
**Category:** Get Help\
**Tags:** question\
**Created:** [November 24, 2020, 5:49pm UTC](https://discourse.openondemand.org/t/open-specific-jupyter-ipynb-when-launching-interactive-app/1225 "2020-11-24T17:49:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brandon-biggs](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/brandon-biggs/32/350_2.png) [@brandon-biggs](https://discourse.openondemand.org/u/brandon-biggs)\
**Post date:** [November 24, 2020, 5:49pm UTC](https://discourse.openondemand.org/t/open-specific-jupyter-ipynb-when-launching-interactive-app/1225/1 "2020-11-24T17:49:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [November 24, 2020, 6:29pm UTC](https://discourse.openondemand.org/t/open-specific-jupyter-ipynb-when-launching-interactive-app/1225/2 "2020-11-24T18:29:27Z")

</div>

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](https://github.com/OSC/bc_osc_jupyter/blob/79b28073440202af8e0d7bd8caeee708c5a58fdc/view.html.erb#L6).

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`.

---

<div class="post-metadata">

**Author:** ![brandon-biggs](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/brandon-biggs/32/350_2.png) [@brandon-biggs](https://discourse.openondemand.org/u/brandon-biggs)\
**Post date:** [November 24, 2020, 8:22pm UTC](https://discourse.openondemand.org/t/open-specific-jupyter-ipynb-when-launching-interactive-app/1225/3 "2020-11-24T20:22:44Z")

</div>

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

```auto
<%-
  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/`

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [November 24, 2020, 8:30pm UTC](https://discourse.openondemand.org/t/open-specific-jupyter-ipynb-when-launching-interactive-app/1225/4 "2020-11-24T20:30:21Z")

</div>

First, I’d be sure you’re actually [using full\_url in the action element of the form](https://github.com/OSC/bc_osc_jupyter/blob/e15c72db16c571390a3f9b6027b28b50f1926d29/view.html.erb#L20).

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).

---

<div class="post-metadata">

**Author:** ![brandon-biggs](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/brandon-biggs/32/350_2.png) [@brandon-biggs](https://discourse.openondemand.org/u/brandon-biggs)\
**Post date:** [November 24, 2020, 8:39pm UTC](https://discourse.openondemand.org/t/open-specific-jupyter-ipynb-when-launching-interactive-app/1225/5 "2020-11-24T20:39:01Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![westburg.2](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@westburg.2](https://discourse.openondemand.org/u/westburg.2)\
**Post date:** [May 26, 2022, 3:43pm UTC](https://discourse.openondemand.org/t/open-specific-jupyter-ipynb-when-launching-interactive-app/1225/6 "2022-05-26T15:43:05Z")

</div>


