plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
20.95k stars 2.02k forks source link

[BUG] adding restyleData to input causing legend selection to clear automatically #2608

Closed crossingchen closed 1 day ago

crossingchen commented 12 months ago

Thank you so much for helping improve the quality of Dash!

We do our best to catch bugs during the release process, but we rely on your help to find the ones that slip through.

Describe your context Please provide us your environment, so we can easily reproduce the issue.

Describe the bug

After adding restyleData in Input in @app.callback like below: @app.callback( Output("graph", "figure"), Input("input_1", "value"), Input('upload-data', 'contents'), Input("graph", "restyleData"), ) When I click or double click on a legend, initially the graph is updated correctly (e.g. removing the data series if single clicked, or only showing the data series is double clicked). But then the graph is reverted back to its initial state automatically (i.e. all data series are shown) after a certain period of time (depending on the size of the df). If I click or double click the legend the second time, the graph does not revert back automatically. If I click or double click the third time, the graph reverts back again automatically...and so on. To isolate the issue, the restyleData input is not used anywhere in the function (e.g. def update_line_chart(input_1, contents, restyleData)) but in a print statement. But the restyleData content prints out correctly it seems.

Expected behavior

When I click or double click on a legend, the update to the graph retains.

Screenshots

If applicable, add screenshots or screen recording to help explain your problem.

https://github.com/plotly/dash/assets/5752865/79f3cdfd-2c13-46c7-8097-98e9fa046217

alexcjohnson commented 11 months ago

A restyle event is triggered when you click on a legend item, because this affects the visible attribute of the traces on the graph. So the callback will fire and return a new figure to the graph. So you can either detect that this isn't an interaction that should provide a new figure, or you can set layout.uirevision to something truthy, which will take the new figure but then apply the same changes made by the user clicks on top of it.

If you'd like to discuss this further, https://community.plotly.com/ is a better place to follow up :)

crossingchen commented 11 months ago

Thanks for the explanation @alexcjohnson. I'm still not 100% clear why the behavior differs when I click the first time (or odd number of clicks) and second time (or even number of clicks). I'm going to try the suggestion you made and post my question on on forum if I'm not able to figure it out.

gvwilson commented 1 day ago

Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are most important to our community. If this issue is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. (Please note that we will give priority to reports that include a short reproducible example.) If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson