jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook

Home Page:https://ipywidgets.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

input widget values cannot be changed by keyboard inputs with `notebook 7.1.x `

orionlee opened this issue · comments

Description


Update: it looks like the issue appears when the virtual environment is upgraded from notebook 7.0.x to 7.1.x, and requires a "Empty Cache and Hard Reload" for the widgets to work. I don't know if the issue can be considered closed, or there should be a work item for ipywidgets / notebook to prevent it from happening in the future.


Input widgets (e.g., FloatText) do not appear to work with notebook v7.1.0 or later.
After the widgets are rendered, changing the value of a input widget by typing a new value would:

  • make the cell display disappear
  • the code cell is changed to Markdown type, with the first line prepended with #### .
  • some javascript errors in developer console (see below)

Related:

  1. After the widgets are rendered, if one tries to change the value of the (numeric) input widget with up/down arrow keys, the value is not changed. Instead, the focus is shifted to the cell above / below.
  2. If one tries to change the value of the input widget with mouse wheel (or click the up/down arrow next to the input box), everything works (the value is updated, and the plot is updated accordingly).

Reproduce

With ipywidgets 8.x and notebook 7.1.x:

  1. Run the example notebook below
  2. Click the 't0' input control
  3. Replace the value with something else, e.g., 3.0
  4. the errors described above occur.

A screen recording:
ipywidgets_notebook_compat_issue

Example notebook

#%% cell 1
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as matplotlib

from ipywidgets import interactive_output
import ipywidgets as widgets; print("ipywidgets:", widgets.__version__)
import notebook as nb; print("notebook:", nb.__version__)


#%% cell 2
%matplotlib inline

def _update_plot(t0, surround_time):
    ax = plt.figure(figsize=(12, 4)).gca();
    x = np.linspace(0, 10, num=100)
    y = np.sin(x)
    ax.scatter(x, y);
    ax.set_xlabel("time");
    if t0 >= 0:
        ax.axvline(t0, 0, 0.3, linestyle="--", label="t0");
        if surround_time > 0:  # zoom around t0 if specified
            ax.set_xlim(t0 - surround_time / 2, t0 + surround_time / 2)
    ax.legend();
    return ax


def plot_interactive(initial_t0):
    # the control
    t0 = widgets.FloatText(
        value=initial_t0,
        step=0.1,
        description=r"t0, -1 for unspecified",
    )
    surround_time = widgets.FloatText(
        value=-1, step=0.5, description="zoom (days)",
    )

    # Layout the UI controls
    VB = widgets.VBox
    HB = widgets.HBox
    ui = VB(
        [
            HB([t0, surround_time]),
        ]
    )

    w = interactive_output(
        _update_plot,
        dict(
            t0=t0,
            surround_time=surround_time,
        ),
    )
    display(ui, w)
    return w


plot_interactive(2.0);

Expected behavior

The interactive widgets should work.
(The same codes work with notebook 7.0.6, but not 7.1.x)

Context

  • ipywidgets version 8.1.2 (the problem also appeared in 8.0.7)
  • notebook version 7.1.3 (the problem also appears in 7.1.0, but not 7.0.6)
  • Operating System and version: Windows 11
  • Browser and version: Chrome v124
Troubleshoot Output
$jupyter troubleshoot
$PATH:
        C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test
        C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\Library\mingw-w64\bin
        C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\Library\usr\bin
        C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\Library\bin
        C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\Scripts
        C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\bin
        C:\pkg\_winNonPortables\miniforge3\condabin
        C:\Users\XYZ\bin
        C:\pkg\PortableGit\mingw64\bin
        C:\pkg\PortableGit\usr\local\bin
        C:\pkg\PortableGit\usr\bin
        C:\pkg\PortableGit\usr\bin
        C:\pkg\PortableGit\mingw64\bin
        C:\pkg\PortableGit\usr\bin
        C:\Users\XYZ\bin
        C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS
        C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS
        C:\Windows\system32
        C:\Windows
        C:\Windows\System32\Wbem
        C:\Windows\System32\WindowsPowerShell\v1.0
        C:\Windows\System32\OpenSSH
        C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
        C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL
        C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
        C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT
        C:\Program Files\Intel\Intel(R) Management Engine Components\IPT
        C:\WINDOWS\system32
        C:\WINDOWS
        C:\WINDOWS\System32\Wbem
        C:\WINDOWS\System32\WindowsPowerShell\v1.0
        C:\WINDOWS\System32\OpenSSH
        C:\pkg\_winNonPortables\MiKTeX\miktex\bin\x64
        C:\pkg\_winNonPortables\LyX 2.3\Perl\bin
        C:\Users\XYZ\AppData\Local\Programs\WingetUI\choco-cli\bin
        C:\Users\XYZ\.cargo\bin
        C:\pkg\PortableGit\usr\bin
        C:\Users\XYZ\AppData\Local\Microsoft\WindowsApps
        C:\pkg\_winDesktopUtils\VSCode
        C:\Users\XYZ\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin
        C:\pkg\PortableGit\usr\bin\vendor_perl
        C:\pkg\PortableGit\usr\bin\core_perl
        C:\pkg\Notepad2
        C:\dev\misc-dev
        C:\pkg\ripgrep
        C:\Users\XYZ\AppData\Roaming\Python\Scripts
        C:\Users\XYZ\.yarn\bin
        C:\Users\XYZ\.config\yarn\global\node_modules\.bin

sys.path:
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\Scripts
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\python312.zip
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\DLLs
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\Lib
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\Lib\site-packages
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\Lib\site-packages\win32
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\Lib\site-packages\win32\lib
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\Lib\site-packages\Pythonwin

sys.executable:
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\python.exe

sys.version:
3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:20:11) [MSC v.1938 64 bit (AMD64)]

platform.platform():
Windows-11-10.0.22631-SP0

where jupyter:
C:\pkg_winNonPortables\miniforge3\envs\ipywidgets-test\Scripts\jupyter.exe

pip list:
Package Version
------------------------- --------------
anyio 4.3.0
argon2-cffi 23.1.0
argon2-cffi-bindings 21.2.0
arrow 1.3.0
asttokens 2.4.1
async-lru 2.0.4
attrs 23.2.0
Babel 2.14.0
beautifulsoup4 4.12.3
bleach 6.1.0
Brotli 1.1.0
cached-property 1.5.2
certifi 2024.2.2
cffi 1.16.0
charset-normalizer 3.3.2
colorama 0.4.6
comm 0.2.2
contourpy 1.2.1
cycler 0.12.1
debugpy 1.8.1
decorator 5.1.1
defusedxml 0.7.1
entrypoints 0.4
exceptiongroup 1.2.0
executing 2.0.1
fastjsonschema 2.19.1
fonttools 4.51.0
fqdn 1.5.1
h11 0.14.0
h2 4.1.0
hpack 4.0.0
httpcore 1.0.5
httpx 0.27.0
hyperframe 6.0.1
idna 3.7
importlib_metadata 7.1.0
importlib_resources 6.4.0
ipykernel 6.29.3
ipython 8.22.2
ipywidgets 8.1.2
isoduration 20.11.0
jedi 0.19.1
Jinja2 3.1.3
json5 0.9.25
jsonpointer 2.4
jsonschema 4.21.1
jsonschema-specifications 2023.12.1
jupyter_client 8.6.1
jupyter_core 5.7.2
jupyter-events 0.10.0
jupyter-lsp 2.2.5
jupyter_server 2.14.0
jupyter_server_terminals 0.5.3
jupyterlab 4.1.6
jupyterlab_pygments 0.3.0
jupyterlab_server 2.26.0
jupyterlab_widgets 3.0.10
kiwisolver 1.4.5
MarkupSafe 2.1.5
matplotlib 3.8.4
matplotlib-inline 0.1.7
mistune 3.0.2
munkres 1.1.4
nbclient 0.10.0
nbconvert 7.16.3
nbformat 5.10.4
nest_asyncio 1.6.0
notebook 7.1.3
notebook_shim 0.2.4
numpy 1.26.4
overrides 7.7.0
packaging 24.0
pandocfilters 1.5.0
parso 0.8.4
pickleshare 0.7.5
pillow 10.3.0
pip 24.0
pkgutil_resolve_name 1.3.10
platformdirs 4.2.0
ply 3.11
prometheus_client 0.20.0
prompt-toolkit 3.0.42
psutil 5.9.8
pure-eval 0.2.2
pycparser 2.22
Pygments 2.17.2
pyparsing 3.1.2
PyQt5 5.15.9
PyQt5-sip 12.12.2
PySocks 1.7.1
python-dateutil 2.9.0
python-json-logger 2.0.7
pytz 2024.1
pywin32 306
pywinpty 2.0.13
PyYAML 6.0.1
pyzmq 26.0.0
referencing 0.34.0
requests 2.31.0
rfc3339-validator 0.1.4
rfc3986-validator 0.1.1
rpds-py 0.18.0
Send2Trash 1.8.3
setuptools 69.5.1
sip 6.7.12
six 1.16.0
sniffio 1.3.1
soupsieve 2.5
stack-data 0.6.2
terminado 0.18.1
tinycss2 1.2.1
toml 0.10.2
tomli 2.0.1
tornado 6.4
traitlets 5.14.3
types-python-dateutil 2.9.0.20240316
typing_extensions 4.11.0
typing-utils 0.1.0
uri-template 1.3.0
urllib3 2.2.1
wcwidth 0.2.13
webcolors 1.13
webencodings 0.5.1
websocket-client 1.7.0
wheel 0.43.0
widgetsnbextension 4.0.10
win-inet-pton 1.1.0
zipp 3.17.0

Command Line Output
$[I 2024-04-19 12:54:03.377 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2024-04-19 12:54:03.393 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-04-19 12:54:03.409 ServerApp] jupyterlab | extension was successfully linked.
C:\Users\XYZ\.jupyter\jupyter_notebook_config.py:266: SyntaxWarning: invalid escape sequence '\d'
  c.NotebookApp.notebook_dir = "C:\dev\_juypter"
[W 2024-04-19 12:54:03.415 JupyterNotebookApp] 'notebook_dir' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2024-04-19 12:54:03.415 JupyterNotebookApp] 'notebook_dir' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2024-04-19 12:54:03.420 ServerApp] notebook_dir is deprecated, use root_dir
[I 2024-04-19 12:54:03.420 ServerApp] notebook | extension was successfully linked.
[W 2024-04-19 12:54:03.843 ServerApp] jupyter_nbextensions_configurator | error adding extension (enabled: True): The module 'jupyter_nbextensions_configurator' could not be found (No module named 'jupyter_nbextensions_configurator'). Are you sure the extension is installed?
    Traceback (most recent call last):
      File "C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\Lib\site-packages\jupyter_server\extension\manager.py", line 323, in add_extension
        extpkg = ExtensionPackage(name=extension_name, enabled=enabled)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\Lib\site-packages\jupyter_server\extension\manager.py", line 187, in __init__
        self._load_metadata()
      File "C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\Lib\site-packages\jupyter_server\extension\manager.py", line 202, in _load_metadata
        raise ExtensionModuleNotFound(msg) from None
    jupyter_server.extension.utils.ExtensionModuleNotFound: The module 'jupyter_nbextensions_configurator' could not be found (No module named 'jupyter_nbextensions_configurator'). Are you sure the extension is installed?
[I 2024-04-19 12:54:03.843 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-04-19 12:54:03.890 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-04-19 12:54:03.890 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2024-04-19 12:54:03.890 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-04-19 12:54:03.906 LabApp] JupyterLab extension loaded from C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\Lib\site-packages\jupyterlab
[I 2024-04-19 12:54:03.906 LabApp] JupyterLab application directory is C:\pkg\_winNonPortables\miniforge3\envs\ipywidgets-test\share\jupyter\lab
[I 2024-04-19 12:54:03.906 LabApp] Extension Manager is 'pypi'.
[I 2024-04-19 12:54:04.260 ServerApp] jupyterlab | extension was successfully loaded.
[I 2024-04-19 12:54:04.260 ServerApp] notebook | extension was successfully loaded.
[I 2024-04-19 12:54:04.260 ServerApp] The port 8888 is already in use, trying another port.
[I 2024-04-19 12:54:04.260 ServerApp] Serving notebooks from local directory: C:\dev\_juypter
[I 2024-04-19 12:54:04.260 ServerApp] Jupyter Server 2.14.0 is running at:
[I 2024-04-19 12:54:04.260 ServerApp] http://localhost:8889/tree?token=954b35e9ed9c2d4f57d1204b06b5dd4cdfbfbf238fe7794c
[I 2024-04-19 12:54:04.260 ServerApp]     http://127.0.0.1:8889/tree?token=954b35e9ed9c2d4f57d1204b06b5dd4cdfbfbf238fe7794c
[I 2024-04-19 12:54:04.260 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-04-19 12:54:04.323 ServerApp]
To access the server, open this file in a browser:
    file:///C:/Users/XYZ/AppData/Roaming/jupyter/runtime/jpserver-24828-open.html
Or copy and paste one of these URLs:
    http://localhost:8889/tree?token=954b35e9ed9c2d4f57d1204b06b5dd4cdfbfbf238fe7794c
    http://127.0.0.1:8889/tree?token=954b35e9ed9c2d4f57d1204b06b5dd4cdfbfbf238fe7794c

[I 2024-04-19 12:54:04.492 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
[I 2024-04-19 12:54:11.947 ServerApp] Saving file at /PH_TESS_LightCurveViewer/Untitled_ipywidgets_notebook_compat_test1.ipynb
[I 2024-04-19 12:54:19.856 ServerApp] Kernel started: b1512e1e-e0cd-496c-b895-0235ba2f5326
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.
[I 2024-04-19 12:54:21.402 ServerApp] Connecting to kernel b1512e1e-e0cd-496c-b895-0235ba2f5326.

Browser Output (after the interactive widgets are rendered, before changing any input widget values)
TypeError: (0 , s.CommonMfracMixin) is not a function
    at 32547 (7369.bundle.js:1:44756)
    at v (bundle.js:1:516)
    at 44383 (7369.bundle.js:1:18916)
    at v (bundle.js:1:516)
    at 46002 (7369.bundle.js:1:18507)
    at v (bundle.js:1:516)
    at 57369 (7369.bundle.js:1:4557)
    at v (bundle.js:1:516)
    at v.t (bundle.js:1:753)
    at async Promise.all (index 1)
Browser Output (after changing the value of the input widget)
Error rendering buttons of the cell toolbar:  TypeError: Cannot read properties of null (reading 'insertWidget')
    at 7386.bundle.js:1:2413
(anonymous) @ 7386.bundle.js:1
Promise.catch (async)
_addToolbar @ 7386.bundle.js:1
_onActiveCellChanged @ 7386.bundle.js:1
a @ 409.bundle.js:1
e.emit @ 409.bundle.js:1
emit @ 409.bundle.js:1
set activeCellIndex @ 4234.bundle.js:1
onCellInserted @ 4234.bundle.js:1
_insertCell @ 4234.bundle.js:1
_onCellsChanged @ 4234.bundle.js:1
_onCellsChanged @ 4234.bundle.js:1
a @ 409.bundle.js:1
e.emit @ 409.bundle.js:1
emit @ 409.bundle.js:1
(anonymous) @ 4234.bundle.js:1
_onSharedModelChanged @ 4234.bundle.js:1
a @ 409.bundle.js:1
e.emit @ 409.bundle.js:1
emit @ 409.bundle.js:1
C._onYCellsChanged @ 35.bundle.js:1
i @ 7957.bundle.js:1
xe @ 7957.bundle.js:1
gr @ 7957.bundle.js:1
_callObserver @ 7957.bundle.js:1
(anonymous) @ 7957.bundle.js:1
i @ 7957.bundle.js:1
Un @ 7957.bundle.js:1
Tn @ 7957.bundle.js:1
transact @ 7957.bundle.js:1
transact @ 35.bundle.js:1
(anonymous) @ 4234.bundle.js:1
e.changeCellType @ 4234.bundle.js:1
e.setMarkdownHeader @ 4234.bundle.js:1
execute @ 2512.bundle.js:1
execute @ 3301.bundle.js:1
_executeKeyBinding @ 3301.bundle.js:1
processKeydownEvent @ 3301.bundle.js:1
evtKeydown @ 6731.bundle.js:1
handleEvent @ 6731.bundle.js:1
handleEvent @ 514.bundle.js:1
12:54:40.416 7386.bundle.js:1 Uncaught TypeError: Cannot read properties of null (reading 'type')
    at h._cellToolbarOverlapsContents (7386.bundle.js:1:3744)
    at 7386.bundle.js:1:3635

Update: The error can be reproduced in the following simpler setup, displaying a FloatText only.
The error also occurs if Text is used instead of FloatText.

%matplotlib inline

def create_widgets(initial_t0):
    # the control
    t0 = widgets.FloatText(
        value=initial_t0,
        step=0.1,
        description=r"t0",
    )

    display(t0)

create_widgets(2);

Update 2: the problem seems to be that the browser has cached some incompatible (javascripts?) assets.

The same code works

  • in incognito mode, or
  • if I do a Empty Cache and Hard Reload.