How to use 'scatter.on_change' to grab event?


I’d like to find some examples for “on_change” function for “Scatter” plot. Just need to send some event when plot is changed (eg. series are hide) to trigger some function which will update another plot (eg. resolve average).

I tried to use it similarly to what I’ve found for ‘scatter.on_click’ but dunno how to get it work. However, this example as well doesn’t work for my case, because I use ‘iplot’. I hope ‘on_change’ don’t worry about ‘iplot’.

Any suggestgions?

Later on, I’ve found I could use @callbacks with relayoutData property.

@app.callback(Output('data-bars', 'figure'), [Input('data-lines', 'relayoutData')])
def upd_graph(reldata):    
    title = str(np.random.randn(1))    
    return { 'data': data, 'layout': layout.update({'title': title}) }

Yes, it triggers events but doesn’t interact with legend. I get print messages about tools activity but not while hiding series in my legend. Which property should I try?

Best for #api:python

Hi @plotlek,

The trace.on_* methods are only designed for use in the Jupyter Notebook with the FigureWidget class. If you’re using Dash, as in your code example, then you’ll need to use the @app.callback approach like you have in your example. The reason that you’re not seeing a callback in response to clicking the legend is that this is considered a restyle rather than relayout event.

Unfortunately, it looks like Dash doesn’t have support for restyle events yet. See for current status.

Hope that helps clear things up.