Search code examples
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:

    • Clic on the "Edit" button
    • Save the notebook
    • Close the browser window
    • Annd open the notebook again.

    You should see a floating TOC window.

    If not, go to the next step.

    Step 1 - Is this a Jupyter problem?

    • Check the jupyter_contrib_nbextensions is installed (pip freeze | grep jupyter_contrib_nbextensions).

    • Open jupyter and check there is a 'Nbextensions' tab next to the 'Clusters' tab on the home page.

    • Open the 'Nbclusters' tab and leave unchecked the ' disable configuration for nbextensions without explicit compatibility (they may break your notebook environment, but can be useful to show for nbextension development)' box.

    • Now look for the 'Table of contents (2)' extension and enable it.

    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:

    • Another browser (chrome, firefox, Edge..)
    • Or your 'normal' browser in incognito/InPrivate mode

    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:

    • If the Clean browser works, but the "normal" browser doesn't
      • clear cache in the normal browser and try again.
    • If the Clean browser does not work and Jupyter is running on your local machine.
      • We've hit a bug here.
      • Open your browser developer tools, open a ticket in github, and add the console output from developer tools.
    • If the Clear browser does not work and Jupyter is running on a remote machine
      • Do you use a proxy? or is your ISP using transparent caching for this page/parts of the page (last one is hard to assess).
        • Try running Jupyter in another port (with the --port option). That should fix he problem. Consider using https instead of http to avoid caching by intermediate network.