I have a pip package / nbextension for an HTML/JS visualization I’ve built, as documented here.
It works great when you run those nbextension commands on the command line to install/enable it, then run a notebook server and use it. But, in situations like Kaggle Kernels, where people don’t have access to a persistent environment which runs the notebook kernel, the installation story isn’t as clean.
They can pip install and jupyter nbextension install/enable in a cell of their notebook by prepending those commands with “!” to indicate that they are shell commands. But, if they run that cell and then try to use the extension, the nbextension fails to visualize, with console errors such as:
“Error: Could not create a view for model id …” and “require.js?v=6da8be361b9ee26c5e721e76c6d4afce:165 Uncaught (in promise) Error: Script error for “wit-widget””
This can be seen in the following Kaggle Kernel where I try to use the What-If Tool extension - https://www.kaggle.com/jameswex/what-if-tool-usage-in-kaggle-kernels/ (you can fork the kernel and run the cells). After running the first cell, the last cell will have that error described above, UNLESS you refresh the webpage before running the cell that uses the nbextension. If you refresh the page, then run that cell, it visualizes correctly.
I’m wondering exactly why this failure happens, and why it is fixed by refreshing the page before running the cell that uses the extension. Hopefully there is something about my package I can change to avoid this issue, or some call I can make in the notebook to get past the issue without requiring a page refresh.
I see the same issue with the labextension version of my widget for use with JupyterLab - it also has the need to refresh the page after extension installation but before using it, with the same errors.
Any ideas? Thanks for your help!