Start Jupyter notebook directly in an OOD app

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

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:

<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:

<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

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

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.

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

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.

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