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

ipywidgets.Play doesn't work when the control is added after the map. #1226

Open
lopezvoliver opened this issue Aug 20, 2024 · 1 comment
Open

Comments

@lopezvoliver
Copy link
Contributor

As mentioned in the title, adding a control with a Play widget after the map is displayed somehow messes up the Play widget.

Here's the code to reproduce the normal behavior:

import ipyleaflet
import ipywidgets

m = ipyleaflet.Map(zoom=5, center=(40,-120))
play = ipywidgets.Play()
slider = ipywidgets.IntSlider(max=10)
box = ipywidgets.HBox(children=[play,slider])
control = ipyleaflet.WidgetControl(widget = box, position="topright")
ipywidgets.jslink((play,'value'),(slider,'value'))
m.add(control)
m

ipyleaflet-normal-play

Here's what happens if we move the m.add(control) line to another cell:

ipyleaflet-bug-play

Here's a slightly larger reproducible example that might be useful:

  1. Add the control with the slider to the map and display the map.
  2. In a new cell, display the Play widget. It works as expected.
  3. In a new cell, add the Play widget to the map --> the issue is reproduced.

ipyleaflet-bug-play-ext

@lopezvoliver
Copy link
Contributor Author

A workaround for this is to add the ipyleaflet.WidgetControl with an empty HBox widget (or VBox). The Play widget can be added later to the box and works as expected:

import ipyleaflet
import ipywidgets

m = ipyleaflet.Map(zoom=5, center=(40,-120))
play = ipywidgets.Play()
slider = ipywidgets.IntSlider(max=10)
box = ipywidgets.HBox()  # Empty box
control = ipyleaflet.WidgetControl(widget = box, position="topright")
ipywidgets.jslink((play,'value'),(slider,'value'))
m.add(control) # Add empty control BEFORE displaying map
display(m)

and then..

box.children = [play, slider]

ipyleaflet-bug-play-workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant