Black Lives Matter. Please consider donating to Black Girls Code today.

Detecting callback from custom updatemenu buttons

Hello all,
I am trying to make plots with multiple sets of custom buttons and I keep updating the data with these buttons. Now the output from one set of buttons depends on the output of a different set. For example, I have a button that switches from A vs B to A vs C. Then I have a button for linear fit - but the linear fit will depend on whether it’s A vs B or A vs C. Is there a way to know which button is clicked from the code so that I can use that as an input for the second set of buttons? Or else, is there any other way to do this?

Basically I am looking for a way to find which button was clicked.

Many Thanks,
Adi

Hi. Can you be more precise about the buttons you’re using? Are these pure HTML <buttons>, plotly.js updatemenu buttons or anything else?

Sorry. I’m using plotly.js updatemenus buttons.

Each updatemenus button is map to a Plotly[method]. For example if you have

updatemenus: [{
  buttons: [{
    label: 'my button',
    method: 'restyle',
    args: ['marker.color', 'red']
  }]
}]

in your layout object, then clicking on that button will emit plotly_restyle with event data {'marker.color', 'red'}. So by attaching a listentener as graphDiv.on('plotly.restyle, () => {}) you should be able to detect updatemenu button callbacks.

1 Like

Awesome, thank you very much.

1 Like

Following up on this question:

What if it’s desired to have a callback on the dash server side (as opposed to the JS client side?)
Is there a way to setup a callback to do that?
I’m actually using the buttons to update the selectedpoints property, and was hoping that would trigger the selectedData event, but that doesn’t work.

I also tried having the callback trigger on relayoutdata but it doesn’t do anything.