# Start Jupyter notebook directly in an OOD app

**URL:** <https://discourse.openondemand.org/t/start-jupyter-notebook-directly-in-an-ood-app/1315>\
**Category:** Get Help\
**Created:** [February 10, 2021, 5:19am UTC](https://discourse.openondemand.org/t/start-jupyter-notebook-directly-in-an-ood-app/1315 "2021-02-10T05:19:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcuma](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/mcuma/32/171_2.png) [@mcuma](https://discourse.openondemand.org/u/mcuma)\
**Post date:** [February 10, 2021, 5:19am UTC](https://discourse.openondemand.org/t/start-jupyter-notebook-directly-in-an-ood-app/1315/1 "2021-02-10T05:19:58Z")

</div>

We have a professor who has created Jupyter notebooks (\*.ipynb) for his assignments, and would like the OOD Jupyter Notebook app to start the notebook directly. It is possible from the command line as:  
jupyter notebook path\_to/file.ipynb

But, if I put the same into the template/script.sh of our Jupyter NB app:  
jupyter notebook --config="${CONFIG\_FILE}" path\_to/file.ipynb  
the notebook does not start, only the generic Jupyter entry page.

I suspect that’s because of the use of the --config, but, I can’t gather from the docs if there’s a config entry for the notebook file, or, what else can be causing the notebook not to start when opening the app.

Anyone has any thoughts about this, or have succeeded in this?

Ultimately, we’d like to run the notebook too, kind of what Binder does using Voila, but, Voila does not accept the Jupyter server --config option that we need in the OOD to set things like the port, no open\_browser, etc.

Thanks,  
MC

---

<div class="post-metadata">

**Author:** ![mcuma](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/mcuma/32/171_2.png) [@mcuma](https://discourse.openondemand.org/u/mcuma)\
**Post date:** [February 10, 2021, 8:34pm UTC](https://discourse.openondemand.org/t/start-jupyter-notebook-directly-in-an-ood-app/1315/2 "2021-02-10T20:34:46Z")

</div>

Digging a bit more into the specific notebook launch.

If I put the following to template/script.sh.erb:  
`jupyter notebook --config="${CONFIG_FILE}" /uufs/chpc.utah.edu/common/home/u0101881/software/pkg/miniconda3-dgoldenberg/app/Experiment_2/exp2_sim.ipynb`

Pushing the “Connect to Jupyter” button in OOD launches the Jupyter main screen, in URL `https://ondemand.chpc.utah.edu/node/notch081.ipoib.int.chpc.utah.edu/32537/tree?` This seems to be defined in the “view.html.erb” which defines the button:

```auto
<form action="/node/<%= host %>/<%= port %>/login" method="post" target="_blank">
  <input type="hidden" name="password" value="<%= password %>">
  <button class="btn btn-primary" type="submit">
    <i class="fa fa-cogs"></i> Connect to Jupyter
  </button>
</form>

```

Now, I start the Jupyter with the running notebook (as shown above), so, if I type the following into a new browser tab, without starting the notebook from the Jupyter main screen, I get the notebook started: `https://ondemand.chpc.utah.edu/node/notch081.ipoib.int.chpc.utah.edu/32537/notebooks/Experiment_2/exp2_sim.ipynb`

So, I am trying to define a new button in the `view.html.erb`, as:

```auto
<form action="/node/<%= host %>/<%= port %>/notebooks/Experiment_2/exp2_sim.ipynb" method="post" target="_blank">
  <button class="btn btn-primary" type="submit">
    <i class="fa fa-cogs"></i> Connect to Experiment 2
  </button>
</form>

```

But get an error, `405 : Method Not Allowed`. I suspect that’s because I am doing something wrong in the form, but, not knowing much about this particular HTML syntax I am at a loss.

Any quick fix thoughts about this?

Thanks,  
MC

---

<div class="post-metadata">

**Author:** ![mcuma](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/mcuma/32/171_2.png) [@mcuma](https://discourse.openondemand.org/u/mcuma)\
**Post date:** [February 10, 2021, 8:56pm UTC](https://discourse.openondemand.org/t/start-jupyter-notebook-directly-in-an-ood-app/1315/3 "2021-02-10T20:56:02Z")

</div>

One more thing on the `view.html.erb` button. The `password` is necessary, since the Jupyter is password protected.

The error is suggesting that the “method is not allowed”, so, I removed the `method="post"`, but, then, the notebook page comes up asking for a password, so, that suggests that the `password` is not relayed to the URL, as it would be if the `method="post"` were enabled.

Perhaps the Jupyter notebook is not design to accept the `post` requests? Then how else to supply the password to the notebook page? Just clutching at straws here.

Thanks,  
MC

---

<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:** [February 10, 2021, 9:43pm UTC](https://discourse.openondemand.org/t/start-jupyter-notebook-directly-in-an-ood-app/1315/4 "2021-02-10T21:43:57Z")

</div>

Hey, yea `/login` is a POST request with the form, but you can specify what the next url is in the query param. Here’s how we do something similar in our jupyter installation where `next_url` is a GET to the specific directory you’re trying to go to.

> <https://github.com/OSC/bc_osc_jupyter/blob/master/view.html.erb>

---

<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:** [February 10, 2021, 9:48pm UTC](https://discourse.openondemand.org/t/start-jupyter-notebook-directly-in-an-ood-app/1315/5 "2021-02-10T21:48:42Z")

</div>

On other thing to note is that variable `jupyter_api` there is part of our connection paramaters.

> <https://github.com/OSC/bc_osc_jupyter/blob/bf5023f460ff27c7e83747173fe71287ff7ba972/submit.yml.erb#L41-L42>

So we generate it in the `template/before.sh.erb` and export it here as an environment variable. It’s based off of a few things, namely modules load statements that are only known at runtime, that’s why we have to use it in this way: generate it in the script → write it out to the connection.yml through the conn\_params and then read it back in to the view.html.erb.

---

<div class="post-metadata">

**Author:** ![mcuma](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/mcuma/32/171_2.png) [@mcuma](https://discourse.openondemand.org/u/mcuma)\
**Post date:** [February 10, 2021, 10:20pm UTC](https://discourse.openondemand.org/t/start-jupyter-notebook-directly-in-an-ood-app/1315/6 "2021-02-10T22:20:16Z")

</div>

Thanks Jeff, that did the trick for loading the notebook. I also like your settings for the class pages/NOTEBOOK\_ROOT. I think it may be useful to go over how OSC does their class support with OOD in some future webinar, including detailing your Jupyter app settings for it. We here at Utah went from one class last summer to about 5 today so the growth is non-linear.

Do you have some professors executing the notebooks upon loading as well? I am googling that now but as with most Python things, there are 10 different ways to do it, and I haven’t find one that works yet.

Thanks,  
MC

---

<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/start-jupyter-notebook-directly-in-an-ood-app/1315/7 "2022-05-26T15:43:00Z")

</div>


