I use classic Jupyter Notebook on an Ubuntu 20.04 Server, that runs Apache.
Therefore, when Jupyter runs, I do not access it with localhost:8888, but instead it is proxied to myserver.com/subdir; generally, all works with classic Jupyter notebook as such (I can use ipywidgets, I can control matplotlib/plotly/bokeh plots).
Then, I learned about voila
- I merely installed it via pip3
, and my Jupyter installation picked it up, and shows it as an nbextension. I somehow got to these command line options to start my Jupyter server:
/home/web/Jupyter/notebook/bin/jupyter-notebook --config=/home/jupyter/.jupyter/jupyter_notebook_config.py --Voila.base_url=/subdir/ --VoilaConfiguration.enable_nbextensions=True
Some of these options are also mentioned here Voilà for Jupyter notebooks (bear_classifier; lesson 2) - Part 1 (2020) - Deep Learning Course Forums; in any case, with this, I get a "Voilà" button in the toolbar of an open notebook.
So, if my original notebook link is at https://myserver.com/subdir/notebooks/test.ipynb
, clicking the "Voilà" button shows me https://myserver.com/subdir/voila/render/test.ipynb
- and in fact, I do get the text rendered inside (as well as Pandas DataFrame outputs), so - so far, so good.
Unfortunately, I still do not get any ipywidgets nor plots. Looking at my JavaScript console, I realized a whole bunch of requested JS files are 404-ing (that is, are not found) - and this is also visible in the Jupyter server log, when started from the command line:
[I 13:41:52.743 NotebookApp] Kernel started: b7762a2c-f99b-4a9b-ab64-0910c81a4160, name: python3
[W 13:41:55.615 NotebookApp] No handler found for comm target 'matplotlib'
[W 13:41:57.305 NotebookApp] 404 GET /subdir/voila/jquery.js (127.0.0.1) 7.180000ms referer=http://localhost:8888
[W 13:41:57.306 NotebookApp] 404 GET /subdir/voila/base/js/namespace.js (127.0.0.1) 7.690000ms referer=http://localhost:8888
[W 13:41:57.312 NotebookApp] 404 GET /subdir/voila/services/config.js (127.0.0.1) 1.160000ms referer=http://localhost:8888
[W 13:41:57.314 NotebookApp] 404 GET /subdir/voila/notebook/js/codecell.js (127.0.0.1) 0.980000ms referer=http://localhost:8888
[W 13:41:57.321 NotebookApp] 404 GET /subdir/voila/base/js/events.js (127.0.0.1) 5.060000ms referer=http://localhost:8888
[W 13:41:57.322 NotebookApp] 404 GET /subdir/voila/codemirror/lib/codemirror.js (127.0.0.1) 1.000000ms referer=http://localhost:8888
[W 13:41:57.324 NotebookApp] 404 GET /subdir/voila/codemirror/addon/fold/foldcode.js (127.0.0.1) 0.920000ms referer=http://localhost:8888
[W 13:41:57.338 NotebookApp] 404 GET /subdir/voila/codemirror/addon/fold/brace-fold.js (127.0.0.1) 1.440000ms referer=http://localhost:8888
[W 13:41:57.345 NotebookApp] 404 GET /subdir/voila/codemirror/addon/fold/indent-fold.js (127.0.0.1) 5.140000ms referer=http://localhost:8888
...
This was even without the Voila.base_url
parameter - which I added in the above command line, in hopes that it would solve this issue, which it clearly didn't.
At least, I can confirm from JavaScript console in Firefox, that these 404's are responded back by TornadoServer (the server serving Jupyter), not by Apache.
Also there are these messages in Firefox JavaScript console:
...
The resource from “https://myserver.com/subdir/voila/codemirror/lib/codemirror.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
testplots.ipynb
Loading failed for the <script> with source “https://myserver.com/subdir/voila/codemirror/lib/codemirror.js”.
...
(EDIT: when normal jupyter notebook succeeds in loading, it is from a URL like https://myserver.com/subdir/static/components/codemirror/addon/fold/foldcode.js
)
I suspected this to be due to a misconfiguration of MIME types, but since the same file(s) is reported in the 404, I guess that is the browser reacting on the MIME type of 404 message - so all should be as expected there.
I'm almost certain these 404's occur due to the "subdir/" path when proxying - but I'm at a loss, how to tell voila
to take that into account.
Would anyone have any idea how to fix this, so .js files can be downloaded, and voila rendering can work in full?
EDIT: Possibly relevant: When using --enable_nbextensions=True
, getting lots of 403 errors on base/js/*.js
files · Issue #733 · voila-dashboards/voila:
Seems like some extensions need jquery and base/js/*.js files to be loadable via RequireJS?
...
That is because voila cannot see the difference between extensions that are for jupyter-widgets, and jupyter notebook specific extensions (which will not, and cannot be supported). So these extensions assume a Notebook environment, where these modules are defined (or available), but they are not. The 404's are ok, they just aren't there, and even if they were there they wouldn't work. Best approach is not to install extensions in the Python environment that are notebook specific.