Python Jupyter notebook widgets not rendering/updating properly on Binder

251 Views Asked by At

I am developing a small, python-based conceptual model based around ocean optics. This model uses a series of interactive widgets to update a plot of a curve. The code can be found here; https://gitlab.com/benloveday/oc_forward_model (with a link to the Binder spin-up).

The main "guts" of the interactive component are in the ./forward_model/main.py module, where the parent class is defined. The interactive part is heavily based on the use of the "observe" method, as detailed in https://kapernikov.com/ipywidgets-with-matplotlib/.

The model works perfectly locally, but when deployed on Binder the plots do not render, as shown in the images; local deployment binder deployment

There is no error message when I use the widgets, and they will "move" but without any apparent effect.

Jupyter Notebook classic is used in both cases, I think. It is a little hard to tell if Binder is just using a classic interface over JupyterLab, but the conda env dumps look mostly consistent between local and binder.

Simply changing the matplotlib backend does not help, resulting in a static plot that renders but does not respond to the widgets.

I'm at a little bit of a loss now, and any suggestions/advice on where the issue may lie would be appreciated.

Thanks, Ben

1

There are 1 best solutions below

1
On BEST ANSWER

By specifying a complex environment.yml, you are messing up the basic infrastructure that MyBinder uses or pinning old versions that aren't compatible with all the components MyBinder specifies or maybe compatible with the ones you don't pin(?). (I believe. I actually test in GitHub but I don't think that GitLab vs. GitHub as the source is the difference.)

I can demonstrate this. I imported your repo and made simpler environment.yml in a subdirectory named binder (link to that subdirectory). The environment.yml file was based on the one in the Binder Conda example presently. By placing the environment.yml in the binder subdirectory, you can leave your root environment.yml that allows you to work with it locally, but MyBinder will use the environment.yml inside binder for building images it will launch via the MyBinder system.

Go here and press 'launch binder'. (To launch directly you can also click here.)

You'll see it works now. It also works in JupyterLab now, too. (Ipywidgets-based coding working in JupyterLab tends to provide more evidence you are using currently supported approaches for working with ipywidgets, and so sometimes it is good to check it works in both.)

Changing the configuration is the only thing I did besides pointing at my repo URL from the launch badge and so I think that nails down the issue was your overly complex configuration.

Once you've established yours works incorporating these suggestions, you can try pinning to the current versions being used in the environment.yml in the binder subdirectory and see if it breaks. In the the long run though it is generally better to not pin in the MyBinder configuration files and let the current versions that work well together and work with the underlying structural components determined by the MyBinder system be the versions used.