How to detect when a trace visibility status is changed?

I would like to be able to save the visibility state (i.e. shown or hidden) associated with each trace so that when the plot needs to be redrawn (e.g. user navigates to another view in the app then comes back to one that uses plotly.js) the app can set visibility: 'legendonly' on the traces that the user had previously hidden.

It looks like the plotly_restyle event fires in this case, and I can see the update in the eventData. Is that the recommended way to do this (or at least an appropriate place to put the related code)?

the app can set visibility: ‘legendonly’ on the traces that the user had previously hidden.

I think you’re looking for visible: 'legendonly'. visibility isn’t a proper plotly.js attribute.

Yes.

Oops, yes, I meant visible (Freudian slip from CSS ;D)