Creating a bar chart with selected_points doesn't save the data to the SelectedData

Hi guys.

why does creating the figure with selectedpoints does not register those points to the SelectedData?
(the rest of the post explains what I am trying to do.)

I have a callback that filters well a couple of components but let’s focus only on the bar charts.
Important note: the callback uses only pattern matching of ALL.
I have tried 2 ways to make this work, so I will go over them one by one.

The first way:
let us say we have 2 bar charts.
I select data in one of them, and it triggers the callback. It goes over each id in the outputs. which includes the triggering id.
it runs two checks for each id in the output for the bar chart figures:

  1. Is the id the triggering id?
  2. does the chart have selecteddata?
    if one of them is true then for that figure we return dash.no_update

now if we select data in one figure everything goes well!
if we deselect the data everything also goes well!

BUT, if we select data in the second figure, the first graph also changes.
which is a problem, it’s supposed to have selecteddata but when I run a check I see that the selecteddata is empty.
even though we had selected data before we selected data from the second figure.
I pass the selected points this way:

go.Bar(
            x=values,
            y=categories,
            orientation='h',
            selectedpoints=selected_points
        )

I double-checked that I pass the data and create the figure with the selectedpoints and I do.

so why does it not register in the SelectedData?

The Second Way:
we just don’t do any of the checks from the first way and we build the figures for the triggering graph as well, with the selected points of course.
so they’re supposed to be selected?
but the callback triggers right after we select the data once again (the triggering factor is because SelectedData is empty after we create the figure again), without any SelectedData in the triggering graph the figures go back to the original graphs before they were filtered (the new filtering factor is nothing SelectedData is empty).

So, any idea why creating the figure with selectedpoints does not register those points to the SelectedData?

Anyone? I really can’t figure this one out :L

@adamschroeder @AnnMarieW Sorry to tag you I think you would want to know.
In the docs, you have a bug. Part 4. Interactive Graphing and Crossfiltering | Dash for Python Documentation | Plotly

In the Generic Crossfilter Recipe If you run the code, you encounter the exact same problem I have, so I am starting to think my problem is a bug.

The selectedData property is not updated so the moment we return the new figure the callback is called again. now the selectedpoints_local variable will never be null its always a dictionary with points or {‘points’:}, so we get an error but if we change the if to:

if selectedpoints_local and selectedpoints_local['points'] and selectedpoints_local['range']:

we lose the selectedData.

hi @Matan
Thank you for letting us know about this bug. I’d like our technical writers to see this as well so they can start working on a fix.

Would you like to open an issues in our repo so you can get credit for it, or do you prefer that I open the issue?

I will work on opening an issue :} funny to say but glad I found a bug means I helped :smile:

1 Like

Hopefully, I managed to explain the problem :smile: