Running Jupyter Book as a client

If I have Jupyter Book being served as a site in a container where I am also running a Jupyter notebook server, is there a(n easy) way of configuring Jupyter Book so that ThebeLab / nteract code is executable against the local server?

THe notebook UI is not necessarily best for instructional material where you just want students to run code they are provided with, and Jupyter Book could be good for this.

I could also imaging serving Jupyter Book via nbserverproxy, then stepping into the notebook UI to run code in a notebook a bit more freely rather than through the ThebeLab widgets in the Book UI.

1 Like

Right now, it’s not possible (at least, I don’t think it is…maybe with some light hacking, but it’s certainly not “officially” possible). However I think this would be really awesome. Feel free to open up an issue about this one in the jupyter-book repo!

I think you answered your question in your blog post where you link to running thebelab with a local server.

If that isn’t the answer, could you re-ask the question because in that case I don’t understand it.

(Wanted to leave a pointer to the answer for people from the future, instead of having a thread that ends with no solution.)

Yes, sorry for not posting here…

To answer my own question, it is possible to use Jupyter Book to serve ThebeLab interactions via a local server.

Via here, the template at https://github.com/jupyter/jupyter-book/blob/cce2e7294a8942d5a9a6df844dce03287d813cc7/jupyter_book/book_template/_includes/js/thebelab.html#L7-L21 is currently:

 <script type="text/x-thebe-config">
    {
      requestKernel: true,
      binderOptions: {
        repo: '{{ site.binder_repo_org }}/{{ site.binder_repo_name }}',
        ref: '{{ site.binder_repo_branch }}',
      },
      codeMirrorConfig: {
        theme: "{{ site.codemirror_theme }}"
      },
      kernelOptions: {
        name: '{% if page.kernel_name %}{{ page.kernel_name }}{% else %}python3{% endif %}',
      }
    }
</script>

(I’m not sure what requestKernel does?)

A purely local kernel requires a template of the form:

<script type="text/x-thebe-config">
  {
    bootstrap:{{ site.thebe_bootstrap }},
    kernelOptions: {
      name: "python3",
      serverSettings: {
        "baseUrl": "{{ site.kernel_url }}",
        "token": "{{ site.kernel_token }}"
      }
    },
  }
</script>

where kernel_url and kernel_token could be set via the config template.

The Jupyter server needs starting with some permission setting:

jupyter notebook --NotebookApp.allow_origin='*' --NotebookApp.token=letmein

1 Like