✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

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

Hello.

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 https://plot.ly/python/click-events/ 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))    
    print(reldata)
    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 https://github.com/plotly/dash-core-components/issues/197 for current status.

Hope that helps clear things up.
-Jon