danielfrg / jupyter-flex

Build dashboards using Jupyter Notebooks
https://jupyter-flex.danielfrg.com
Apache License 2.0
316 stars 54 forks source link

Stuck on "... building dashboard ..." and 404 GET /voila/templates/flex/static/jupyter-flex-embed.js #169

Open jmp75 opened 1 year ago

jmp75 commented 1 year ago

I am trying to upgrade an environment to use the latest versions of jupyter-flex and dependencies. I cannot get the dashboard to display.

Repro

Conda environment created using mambaforge include:

voila                     0.5.4              pyhd8ed1ab_0    conda-forge
ipywidgets                8.1.1              pyhd8ed1ab_0    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jupyter-flex              0.9.1              pyhd8ed1ab_0    conda-forge
nbconvert                 7.9.2              pyhd8ed1ab_0    conda-forge

Starting my app with:

voila \
    --template=flex \
    --no-browser \
    --VoilaConfiguration.file_allowlist ".*" \
    --MappingKernelManager.cull_interval=60 \
    --MappingKernelManager.cull_idle_timeout=900 \
    Biomass.ipynb

Observation

kernel starts and visibly notebook cells are being run. The format is looking "raw" however

Then it remains stuck on:

... building dashboard ...

the command line reports:

Could not open static file '/usr/share/jupyter/nbconvert/templates/base/static/jupyter-flex-embed.js'
404 GET /voila/templates/flex/static/jupyter-flex-embed.js (127.0.0.1) 1.36ms

dong a disk search it appears indeed that jupyter-flex-embed.js is not under my new conda environment, but is present in my previous environment "my_prod_environment/" which was using jupyter-flex 0.7.x:

/home/xxxabc/mambaforge/envs/my_prod_environment/lib/python3.9/site-packages/jupyter_flex/templates/nbconvert/flex/static/jupyter-flex-embed.js
Paul-Aime commented 10 months ago

Similar problem here, with both jupyter-flex-embed.css and jupyter-flex-embed.js files.

But for me the browser is first stuck on a page with "Opening Voila-Flex | This page should redirect you to your app. If it doesn't, click here.".

At this point I already have a 403 GET /voila/static/jupyter-flex-embed.css (127.0.0.1): jupyter-flex-embed.css is not in root static directory error.

Then if I click on "click here", I get following similar errors: 404 GET /voila/templates/flex/static/jupyter-flex-embed.css (127.0.0.1) 2.25ms and Could not open static file '/usr/share/jupyter/nbconvert/templates/base/static/jupyter-flex-embed.js'

Also, I don't have any of the 2 missing files at expected location (miniconda3/envs/voila/share/jupyter/nbconvert/templates), neither in any other environment.

$ tree flex/
flex/
├── static/
│  └── favicon.png
├── conf.json
├── flex.j2
└── index.html.j2

Traceback:

$ voila plotly-single.ipynb --template flex
[Voila] Using /tmp to store connection files
[Voila] Storing connection files in /tmp/voila_701bgzit.
[Voila] Serving static files from /home/paul/miniconda3/envs/voila/lib/python3.12/site-packages/voila/static.
[Voila] Voilà is running at:
http://localhost:8866/
403 GET /voila/static/jupyter-flex-embed.css (127.0.0.1): jupyter-flex-embed.css is not in root static directory
403 GET /voila/static/jupyter-flex-embed.css (127.0.0.1) 1.14ms
# ==================================================
# Here I click on "This page should redirect you to your app. If it doesn't, click here.
# ==================================================
[Voila] WARNING | Clearing invalid/expired login cookie username-localhost-8866
[Voila] WARNING | Notebook plotly-single.ipynb is not trusted
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[Voila] Kernel started: 4168b889-28d3-454f-aa28-f7387d1fc132
Could not open static file '/usr/share/jupyter/nbconvert/templates/base/static/jupyter-flex-embed.css'
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
404 GET /voila/templates/flex/static/jupyter-flex-embed.css (127.0.0.1) 1.64ms
[IPKernelApp] WARNING | Unknown error in handling startup files:
404 GET /voila/templates/flex/static/jupyter-flex-embed.css (127.0.0.1) 2.25ms
Could not open static file '/usr/share/jupyter/nbconvert/templates/base/static/jupyter-flex-embed.js'
404 GET /voila/templates/flex/static/jupyter-flex-embed.js (127.0.0.1) 1.15ms
404 GET /voila/templates/flex/static/jupyter-flex-embed.js (127.0.0.1) 1.57ms
^C[Voila] Stopping...
[Voila] Kernel shutdown: 4168b889-28d3-454f-aa28-f7387d1fc132

Environment:

ipywidgets                8.1.1              pyhd8ed1ab_0    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jupyter-flex              0.9.1              pyhd8ed1ab_0    conda-forge
nbconvert                 7.14.0             pyhd8ed1ab_0    conda-forge
voila                     0.5.5              pyhd8ed1ab_0    conda-forge
michelle-ar commented 10 months ago

Hello! Don't know if you still have this problem; it appears that jupyter-flex, ipywidgets and voila have several dependency problems in new versions. The only way I managed to make things work is using these versions of the libraries:

jupyter-flex==0.7.3
nbconvert==6.5.4
voila==0.2.16
ipywidgets==7.8.1
benoitfrisque commented 6 months ago

Hello! Don't know if you still have this problem; it appears that jupyter-flex, ipywidgets and voila have several dependency problems in new versions. The only way I managed to make things work is using these versions of the libraries:

jupyter-flex==0.7.3
nbconvert==6.5.4
voila==0.2.16
ipywidgets==7.8.1

It indeed works for me with this, but I also had to use the following

jinja2==3.0.3
jmp75 commented 6 months ago

For readers of this thread, note there was a security fix to voila, do not use voila==0.2.16 but voila==0.2.17 or above if any in the future. See Voila security updates

benoitfrisque commented 6 months ago

Indeed, I encountered a GitHub warning while working with voila==0.2.16. But when I upgrade to voila==0.2.17, the widgets are constantly loading. Have you found a combination of versions that resolves this, @jmp75 ?

jmp75 commented 6 months ago

@benoitfrisque I've just deployed last night a web app with an upgraded environment voila 0.2.17, and it works fine, so far as I tested interactively. I could operate ipywidget based actions to check my changes.

An environment with the following versions (not quite my prod, but my local dev), includes:

# packages in environment at /home/xxxyyy/myenv:
#
# Name                    Version                   Build  Channel
geopandas                 0.11.1             pyhd8ed1ab_0    conda-forge
illusionist               0.3.0              pyhd8ed1ab_0    conda-forge
ipyevents                 2.0.1              pyhd8ed1ab_0    conda-forge
ipykernel                 6.16.0             pyh210e3f2_0    conda-forge
ipyleaflet                0.17.1             pyhd8ed1ab_0    conda-forge
ipyspin                   0.1.6              pyhd8ed1ab_0    conda-forge
ipython                   8.18.1             pyh707e725_3    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.7.2              pyhd8ed1ab_0    conda-forge
jinja2                    3.0.1              pyhd8ed1ab_0    conda-forge
jupyter-flex              0.8.0              pyhd8ed1ab_0    conda-forge
jupyter_client            6.1.12             pyhd8ed1ab_0    conda-forge
jupyter_core              5.7.2            py39hf3d152e_0    conda-forge
jupyter_server            1.24.0             pyhd8ed1ab_0    conda-forge
jupyterlab                3.4.7              pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.3.0              pyhd8ed1ab_0    conda-forge
jupyterlab_server         2.10.3             pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        1.1.7              pyhd8ed1ab_0    conda-forge
nbclassic                 1.0.0              pyhb4ecaf3_1    conda-forge
nbclient                  0.5.13             pyhd8ed1ab_0    conda-forge
nbconvert                 6.5.3              pyhd8ed1ab_0    conda-forge
nbconvert-core            6.5.3              pyhd8ed1ab_0    conda-forge
nbconvert-pandoc          6.5.3              pyhd8ed1ab_0    conda-forge
pandas                    2.2.2            py39hddac248_0    conda-forge
voila                     0.2.17             pyhd8ed1ab_0    conda-forge
benoitfrisque commented 6 months ago

Thanks @jmp75 , but I get jinja2.exceptions.TemplateNotFound: index.html.j2 when using those.

jmp75 commented 6 months ago

No idea why you get this behavior. I don't know how jinja detects templates provided by other packages. I've had a quick search over the jinja codebase, https://github.com/search?q=repo%3Apallets%2Fjinja%20TemplateNotFound&type=code but this is beyond my know-how.

If I were to encounter this kind of issue I personally may try to run in debug mode to glean more info, but only if I ran out of options to try (like, re-create a conda environment from scratch after messing it up over time). I'd really resort to interactive debug session as a last resort, this is often a rabbit hole.

In case it helps, I have the following VSCode debug configs to handle debugging voila apps, including third party packages via the 'justMyCode' key:

launch.json file to attach to a running python process (like a process already launched with jupyter-flex):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Attach using Process Id",
            "type": "python",
            "request": "attach",
            "processId": "${command:pickProcess}",
            "justMyCode": false
        }
    ]
}

If I need to catch things at process startup immediately

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "jupyter-flex",
            "type": "python",
            "request": "launch",
            "program": "/home/xxxxxx/.venvs/my_env/bin/jupyter-flex",
            "cwd": "/home/xxxxxx/src/biomass/notebooks",
            "args": ["MyDashboard.ipynb", "--VoilaConfiguration.file_whitelist", "\"['.*.json', '.*my_dashboard.css']\"", "--enable_nbextensions=True"],
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ]
}