jupyter-notebooktableofcontentsjupyter-contrib-nbextensions

Some setting changes in Table of Contents 2 (toc2) in nbextensions not showing up in Jupyter notebook I had open at the time of installation


I recently installed nbextensions in my conda environment to add the ability to add a Table of Contents (toc2) to my notebooks. But I did this while having a jupyter notebook open and after installing the extension, changes in the extension settings didn't reflect on the notebook I had open during installation while it did on the others that weren't.

I tried shutting down and restarting the kernel, restarting the computer, and uninstalling and re-installing nbextensions again (following these instructions on a github ticket). None of these things rectified the issue with the notebook that was open. A duplicate of the notebook inherits its problems.

An interesting thing to note is that after reinstalling nbextensions, which was my last attempt, changes of the settings from the first install were held over instead of going back to default (ie color settings in nbextensions being the distinct colors I had switched them to before the uninstall). I'm not sure if I fully uninstalled nbextensions or if it's really possible. And after the re-install, further changes in the settings in the second go-around didn't reflect on any notebooks afterwards, like removing the sidebar toc setting after selecting it the first time, the sidebar remains in certain notebooks.

I'm not sure what's going on but:

1.) Is there a way to get the settings changes to reflect on the notebook universally, particularly having a toc? Especially on the notebook that was open at the time of install?

2.) Is there a way to totally un-install nbextensions like it never existed on my machine so I can try this again?


Solution

  • Step 0 - Is this a problem with the Notebook metadata?

    The toc2 module adds some metadata to the notebook. Just in case this metadata is missing, has wrong values, or the defaults written make the ToC does not show up try this:

    Open the notebook and select "Edit"->"Edit Notebook Metadata".

    Remove the "toc":section if it exists an add this to the end of the metadata:

      "toc": {
        "nav_menu": {},
        "number_sections": true,
        "sideBar": true,
        "skip_h1_title": false,
        "base_numbering": 1,
        "title_cell": "Table of Contents",
        "title_sidebar": "Contents",
        "toc_cell": true,
        "toc_position": {
          "height": "382px",
          "width": "256px",
          "left": "10px",
          "top": "10px"
        },
        "toc_section_display": true,
        "toc_window_display": true
      }
    

    Be careful not to remove any comma(,) after the closing } if exists ! This must be a valid JSON file.

    After changing the metadata:

    You should see a floating TOC window.

    If not, go to the next step.

    Step 1 - Is this a Jupyter problem?

    Now your should see the TOC when you open the notebook.

    If not, go to the next step.

    Step 2 - Is this a browser-related problem?

    Looking at the toc2 extension soure we can see this is client-based based on Javascript code.

    When you load the Jupyter notebook, the module main.js is added to the .js your browser runs and modifies some menu commands.

    To discard we have caching issues, open Jupyter using with a 'fresh' browser. This could be either:

    With a 'clean' browser you should be able to open the notebook and see the navigation bar from the TOC extension.

    What to do now: