-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
Ipywidgets not working if added dynamically #6439
Comments
Hi @anton-br . Found this very old Github entry mentioning the same error and a workaround. Does that help in any way? It seems to mention the package / module that generates the error warning. JuliaGizmos/Interact.jl#176 . Please update this issue if you found a workaround / solution for this. |
@Coderambling thanks for the reply! I tried different versions of ipywidgets/widgetsnbextension but it didn't work. In the issue, they simply add a metadata to Comm. I suspect something needs to be done in |
Regrettably I don't really have specific knowledge of those details of the stack. The only other thing I can suggest is running the code on Anaconda Cloud (or in a similar Notebook environment), and see if the issue persists there. |
Thank you for the suggestion! Unfortunately, I am not sure that switching an environment would help to solve the issue, as I need to start a panel application from the console. I've seen @philippjfr has previously solved this problem before. So, Philip, would you mind to give any clue on how to fix this bug? |
Had a look at the issue you referenced, and looks like some code was changed in ipywidgets_bokeh to solve it. So you're possibly on the right track, but I have no idea beyond that. |
In my testing this is now working but will require a new release of ipywidgets_bokeh. |
yeah, I've also checked and problem with version disappears! @philippjfr, thank you! But, I've found another one. If you try to create interactive pn.pane.Matplotlib instead of slider you'll receive an error "Comm is already created". Feels like someone is trying to create the same comm twice) I'll try to figure out why is happenning and let you know. |
Can you provide a reproducer? |
import ipywidgets as ipw
import panel as pn
import matplotlib.pyplot as plt
pn.extension('ipywidgets')
button = pn.widgets.Button(name='button', width=100)
def calculate(a):
if not a: # aviod widgets creation before button is clicked
return None
fig, ax = plt.subplots()
ax.plot((1, 2, 3))
return pn.pane.Matplotlib(fig, interactive=True, high_dpi=False)
bind_button = pn.bind(calculate, button)
pn.Column(button, bind_button).servable() |
Thanks, also now fixed in bokeh/ipywidgets_bokeh#104 ![]() |
Great is working as intended now! |
Wow that was a quick turnaround @philippjfr ! |
ALL software version info
General:Ubuntu 22.04.2 LTS
python 3.11.3
library versions:
bokeh==3.3.4
ipympl==0.9.3
ipykernel==6.29.3
ipyleaflet==0.18.2
ipympl==0.9.3
ipython==8.22.1
ipython_genutils==0.2.0
ipywidgets==8.1.2
ipywidgets-bokeh==1.5.0
jupyterlab==4.1.2
jupyterlab_pygments==0.3.0
jupyterlab_server==2.25.3
jupyterlab_widgets==3.0.10
matplotlib==3.8.3
panel==1.3.8
browser:
Chrome 122.0.6261.94
Description of expected behavior and the observed behavior
I am trying to dynamically add new widgets by button click. But got a message Wrong widget protocol version: received protocol version '', but was expecting major version '2 and created widgets are not updating. Here is a code example:
If serve the code, push the button and drug the slider, I would expect the slider's value to be printed in floattext widget but nothing happend.
But, from console we can conclude that widgets is updating as expected:
The text was updated successfully, but these errors were encountered: