jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.15k stars 950 forks source link

ipywidgets.interact only updates once inside JupyterLite 0.4.0 #3935

Open lagru opened 2 months ago

lagru commented 2 months ago

Description

It seems that there's an incompatibility between ipywidgets and JupyterLite 0.4.0. When I post the simple snippet below into an empty notebook cell and run it, the slider appears as expected. If I move the slider once the output changes as expected. If I move it again, the output doesn't update anymore.

I didn't find an existing issue on this, apologies if missed one.

Reproduce

  1. Go to https://jupyter.org/try-jupyter/lab/
  2. Verify that JupyterLite is version 0.4.0 under Menu bar > Help > About
  3. Paste the following snippet into the cell of a notebook
%pip install -q ipywidgets

import ipywidgets
print(f"{ipywidgets.__version__=}")

def f(x):
    return x

ipywidgets.interact(f, x=10);
  1. Move slider once -> output updates
  2. Move slider again -> output isn't updated anymore

Expected behavior

The output keeps updating, if the slider is moved multiple times.

Context

I noticed this issue while trying to get scikit-image's tutorials to run in JupyterLite. Initially I thought that using ipywidgets in JupyterLite was not yet possible but then discovered that you include a demo in your docs. I was surprised that it seemed to work fine in your demo and quickly discovered that you are using JupyterLite 0.3.0.

Current plan is to use JupyterLite 0.3.0 then for the tutorial.

Browser Output
Pyodide contents will be synced with Jupyter Contents [index.js:60:28](webpack://jupyterlite/pyodide-kernel-extension/lib/index.js)
Starting WebSocket: wss://jupyter.org/try-jupyter/api/kernels/b1eb5825-59e3-4432-9206-26f19f49d4c2 [default.js:69:20](webpack://_JUPYTERLAB.CORE_OUTPUT/node_modules/@jupyterlab/services/lib/kernel/default.js)
Loading micropip, packaging [pyodide.asm.js:10:93500](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Loaded micropip, packaging [pyodide.asm.js:10:93796](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Failed to fetch ipywidgets through the "jupyter.widget.control" comm channel, fallback to fetching individual model state. Reason: Control comm did not respond in time [327.68dbf8491690b3aff1e7.js:1:5783](https://jupyter.org/try-jupyter/extensions/@jupyter-widgets/jupyterlab-manager/static/327.68dbf8491690b3aff1e7.js?v=68dbf8491690b3aff1e7)
Loading openssl, ssl [pyodide.asm.js:10:93500](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Loaded openssl, ssl [pyodide.asm.js:10:93796](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Loading sqlite3 [pyodide.asm.js:10:93500](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Loaded sqlite3 [pyodide.asm.js:10:93796](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Loading traitlets [pyodide.asm.js:10:93500](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Loaded traitlets [pyodide.asm.js:10:93796](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
traitlets already loaded from default channel [pyodide.asm.js:10:93166](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
sqlite3 already loaded from default channel [pyodide.asm.js:10:93166](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Loading Pygments, asttokens, decorator, executing, ipython, matplotlib-inline, prompt_toolkit, pure_eval, six, stack_data, wcwidth [pyodide.asm.js:10:93500](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Loaded Pygments, asttokens, decorator, executing, ipython, matplotlib-inline, prompt_toolkit, pure_eval, six, stack_data, wcwidth [pyodide.asm.js:10:93796](https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.asm.js)
Note, the `Failed to fetch ipywidgets through the "jupyter.widget.control" comm channel` line appears just after opening an empty notebook.

If using JupyterLab

jtpio commented 1 month ago

Thanks @lagru for the report :+1:

This looks similar to this issue opened on the JupyterLite repo: https://github.com/jupyterlite/jupyterlite/issues/1465

Do you know if this was already an issue with JupyterLite 0.3.0?

bdcodebase commented 2 weeks ago

No, in JupiterLite 0.3.0 it works.