is a reproducible example.
Sometimes it works, but most often when it retrieves the scatter
point index it display the error message
list index out of range:
. . .
5 def trigger_update(trace, points, state):
----> 6 ind = points.point_inds#get the index of the scatter point that is hovered on
8 with fwd.batch_update():#update data and layout in the bar chart
IndexError: list index out of range
What is odd is that it continues to update the bar chart on hover, even after displaying this error.
This behaviour manifests in any other pair consisting in a scatter plot (not only scatermapbox) and other FigureWidget to be updated.
Hi @empet, This is a really cool notebook dashboard!
It looks like the trouble you’re running into is that you have two traces (county boundary lines and country center points) and the
on_hover interaction function is called whenever a hover interaction occurs on either trace. So when a hover is registered on a county boundary, the
on_hover function for the county centers trace is being called with an empty array of points.
Here are two options for getting around this:
- Add a check to your
trigger_update to do nothing if the
point_inds are empty.
def trigger_update(trace, points, state):
if not points.point_inds:
ind = points.point_inds#get the index of the scatter point that is hovered on
with fwd.batch_update():#update data and layout in the bar chart
fwd.data.y = votes_Clinton_Trump[ind]
fwd.layout.title = county_name[ind]
- Set the
hoverinfo property of the country lines trace to
skip instead of
none (as you have it now). When the hoverinfo is
skip, hover events will not be fired.
The reason these empty hover events are fired at the moment is because the
on_selection logic is nearly identical. For
on_selection I wanted empty selection events to fire so that it was possible to respond to the situation where someone selects a region that contains no points. But maybe that should be a special case for
on_selection, so that
on_click don’t fire with empty
What do you think?
@jmmease Thank you very much for your suggestions!!
The first one works but the second leads to the same error.