Ipywidgets: Unable to display sliders or plots render very slowly

Created on 17 May 2018  路  19Comments  路  Source: jupyter-widgets/ipywidgets

Hello,

I have been experimenting with ipywidgets, and have run into very limited success. At first, I was able to properly run a widget with a single float slider, and it would perform perfectly and update real time. However, after copying the code over to another notebook, the slider disappeared and I only had a single frame/plot. Now even testing the basic code from the tutorial does not display sliders.

ipywidgets

I am unsure if I properly installed everything, as I have to pip3 install ipywidgets, otherwise it stats that no module is found for ipywidgets. I am currently on version 7.2.1 for ipywidgets and 3.2.1 for widgetsnbextension.

When trying to debug this issue, I ran into 'widget javascript not detected', 'jupyter widget could not be displayed because the widget state could not be found', and now 'ERROR | No such comm target registered: jupyter.widget.version'. After trial and error experimenting with various versions, I managed to have the sliders in working order again, but the plot would update extremely slowly, and collect a queue of events to process, even for very low computational plots.

Any help would be greatly appreciated, thanks!

Most helpful comment

Thank you all so much for the suggestions! I think the continuous_update=False works okay, but I had mixed effects with the throttling and an error when trying to implementing the debouncing command, about lack of the function get_ioloop(), although it may just be on my end.

Is there any reason why the sliders maintain a queue of inputs? If I continuously move the slider back and forth very quickly, the updates will not keep up and continue through the queue of events slowly. To me this does not really make sense, as it would seem more intuititve to complete the most recent actions and update to the current state.

All 19 comments

It sounds like there a few different versions of packages stomping on each other and not being compatible with each other. I'd recommend a clean install like you had originally.

In particular, the widget javascript not detected error comes from having an old ipywidgets with a new widgetsnbextension package.

Hello, thank you so much for the quick reply! Do you have recommendations on how to perform a clean install? I tried to pip uninstall all both ipywidgets and widgetsnbextension but ran into the same issue.

What does pip freeze and jupyter nbextension list give? Are you using Jupyter notebook or JupyterLab? Are you using an environment system like pipenv or conda? Those will make it much easier to have clean environments.

I personally use conda, which makes it very easy for me to delete an environment and start fresh for different projects.

Pip freeze:
```appnope==0.1.0
backports-abc==0.5
backports.shutil-get-terminal-size==1.0.0
bleach==2.1.3
certifi==2017.7.27.1
chardet==3.0.4
configparser==3.5.0
cycler==0.10.0
decorator==4.3.0
entrypoints==0.2.3
enum34==1.1.6
functools32==3.2.3.post2
futures==3.2.0
-e git+https://github.com/openai/gym@797a25d1b1a8823b305fdb575c4378a5c288b432#egg=gym
html5lib==1.0.1
idna==2.5
ipykernel==4.8.2
ipython==5.7.0
ipython-genutils==0.2.0
ipywidgets==7.2.1
Jinja2==2.10
jsonschema==2.6.0
jupyter-client==5.2.3
jupyter-core==4.4.0
MarkupSafe==1.0
matplotlib==2.0.2
mercurial==4.2.1
mistune==0.8.3
nbconvert==5.3.1
nbformat==4.4.0
notebook==5.5.0
numpy==1.13.0
pandocfilters==1.4.2
pathlib2==2.3.2
pexpect==4.5.0
pickleshare==0.7.4
pip-autoremove==0.9.0
prompt-toolkit==1.0.15
ptyprocess==0.5.2
pyglet==1.2.4
Pygments==2.2.0
pyparsing==2.2.0
pyportmidi==0.0.7
python-dateutil==2.7.3
pytz==2017.2
pyzmq==17.0.0
requests==2.18.2
scandir==1.7
scipy==0.19.1
Send2Trash==1.5.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.11.0
subprocess32==3.2.7
terminado==0.8.1
testpath==0.3.1
tornado==5.0.2
traitlets==4.3.2
urllib3==1.22
wcwidth==0.1.7
webencodings==0.5.1
widgetsnbextension==3.2.1
yasm==0.0

jupyter nbextension list:

Known nbextensions:
config dir: /Users/Patrick/.jupyter/nbconfig
notebook section
jupyter-js-widgets/extension enabled
- Validating: OK
config dir: /usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/etc/jupyter/nbconfig
notebook section
jupyter-js-widgets/extension enabled
- Validating: OK
config dir: /usr/local/etc/jupyter/nbconfig
notebook section
jupyter-js-widgets/extension enabled
- Validating: OK
```
I am unsure if it should have these three config directories.
I am using Jupyter notebooks. I currently am not using an enviroment system, in the past, I had struggles using conda so I have recently been leaning away.

You'll need to clean out those config directories.

jupyter nbextension uninstall --py --sys-prefix widgetsnbextension

Then again without the --sys-prefix

That worked, thank you!

Unfortunately, the sliders are still very slow to update, they still lag behind. Is there any way to prevent that from occurring? If I move a slider back and forth, it will accumulate the inputs and slowly go through each of them.

Is there python code running after each update?

Can you post sample code if so?

I am still using the sample code I mentioned above in the first post.

Does a simple slider work faster?

from ipywidgets import IntSlider, IntText, link
w = IntSlider()
x = IntText()
link((w, 'value'), (x, 'value'))
display(w)
display(x)

If so, it sounds like matplotlib is the one slowing things down - you can use something like bqplot to have faster response time in graphics.

Yes, the code you send above is very fast, it seems that matplotlib is the bottle neck. However, this is very strange as I had all of this code running beforehand it was fast with many calculations, but now even the small sample code is incredibly slow. Is there any method to still utilize matplotlib with decent performance? It seems very strange that it was very fast beforehand then it is abysmally slow now.

That does seem strange. I'm not sure I can help with that - other than again suggesting that you clean everything out and start with a fresh environment.

Thank you, I tried creating a clean conda environment and unfortunately it is still very slow, I am unsure of why. Thank you very much for all your help anyway!

Maybe it is (for some reason) the many events accumulating, please see http://ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html#Disabling-continuous-updates
Or try debouncing: https://github.com/jupyter-widgets/ipywidgets/issues/663 (at the end)

(and FYI, both of those solutions are not speeding things up, rather they are recognizing that matplotlib is relatively slow for this purpose, so they don't ask for updates as often)

Thank you all so much for the suggestions! I think the continuous_update=False works okay, but I had mixed effects with the throttling and an error when trying to implementing the debouncing command, about lack of the function get_ioloop(), although it may just be on my end.

Is there any reason why the sliders maintain a queue of inputs? If I continuously move the slider back and forth very quickly, the updates will not keep up and continue through the queue of events slowly. To me this does not really make sense, as it would seem more intuititve to complete the most recent actions and update to the current state.

Was this page helpful?
0 / 5 - 0 ratings