Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panel tries to set a numeric param to an HTML string when data is updated in the background with a Panel app in a notebook #7014

Closed
1 task
dennisjlee opened this issue Jul 25, 2024 · 0 comments · Fixed by #7038
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@dennisjlee
Copy link
Contributor

I ran into an unusual situation where I set up a simple Panel UI to run inside a Jupyter notebook, and then tried to update the data for the UI from a background thread. I observed that several updates would work properly, but at some point, Panel would try to update the value of a numeric param to be an HTML string (seemingly from a pn.widgets.StaticText) which would throw an exception and stop the UI from updating.

ALL software version info

Python: 3.11.9
OS: Mac OSX 14.5 on M3 Max
Browser: Chrome 126.0.6478.183 (Official Build) (arm64)

Selected python library versions:

bokeh==3.4.3
ipython==8.26.0
notebook==7.2.1
panel==1.4.4
param==2.1.1
pyviz_comms==3.0.2

Description of expected behavior and the observed behavior

It should be possible to update parameterized models from a background thread and have the UI update without issue.

Instead, when I trigger the background thread to update the model repeatedly, at some point Panel handles a message which is trying to set the model's value to be an HTML string, rather than the raw number.
It seems that this may come from the pn.widgets.StaticText widget - if I comment out and only display the position via pn.widgets.FloatSlider, I did not observe this problem in my repro case.

Complete, minimal, self-contained example code that reproduces the issue

See a minimal repro in repo here: https://github.com/dennisjlee/panel-thread-repro

Stack traceback and/or browser JavaScript console output

Traceback (most recent call last):
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/pyviz_comms/__init__.py", line 340, in _handle_msg
    self._on_msg(msg)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/panel/viewable.py", line 478, in _on_msg
    doc.unhold()
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/bokeh/document/document.py", line 776, in unhold
    self.callbacks.unhold()
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/bokeh/document/callbacks.py", line 432, in unhold
    self.trigger_on_change(event)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/bokeh/document/callbacks.py", line 409, in trigger_on_change
    invoke_with_curdoc(doc, event.callback_invoker)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/bokeh/document/callbacks.py", line 444, in invoke_with_curdoc
    return f()
           ^^^
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/bokeh/util/callback_manager.py", line 185, in invoke
    callback(attr, old, new)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/panel/reactive.py", line 474, in _comm_change
    state._handle_exception(e)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/panel/io/state.py", line 458, in _handle_exception
    raise exception
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/panel/reactive.py", line 472, in _comm_change
    self._schedule_change(doc, comm)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/panel/reactive.py", line 454, in _schedule_change
    self._change_event(doc)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/panel/reactive.py", line 450, in _change_event
    self._process_events(events)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/panel/reactive.py", line 387, in _process_events
    self.param.update(**self_params)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 2319, in update
    restore = dict(self_._update(arg, **kwargs))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 2352, in _update
    self_._batch_call_watchers()
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 2546, in _batch_call_watchers
    self_._execute_watcher(watcher, events)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 2506, in _execute_watcher
    watcher.fn(*args, **kwargs)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/panel/param.py", line 527, in link_widget
    self.object.param.update(**{p_name: change.new})
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 2319, in update
    restore = dict(self_._update(arg, **kwargs))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 2345, in _update
    setattr(self_or_cls, k, v)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 528, in _f
    instance_param.__set__(obj, val)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 530, in _f
    return f(self, obj, val)
           ^^^^^^^^^^^^^^^^^
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameters.py", line 543, in __set__
    super().__set__(obj,val)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 530, in _f
    return f(self, obj, val)
           ^^^^^^^^^^^^^^^^^
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameterized.py", line 1498, in __set__
    self._validate(val)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameters.py", line 828, in _validate
    self._validate_value(val, self.allow_None)
  File "/Users/dj/code/panel-thread-repro/venv/lib/python3.11/site-packages/param/parameters.py", line 811, in _validate_value
    raise ValueError(
ValueError: Number parameter 'PositionView.position' only takes numeric values, not <class 'str'>.```

Screenshots or screencasts of the bug in action

panel.bug.screencast.mov
  • I may be interested in making a pull request to address this
@philippjfr philippjfr added this to the v1.4.5 milestone Jul 29, 2024
@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants