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

Any way to choose the lasso select tool programatically with API?

Suppose I have a plotly chart where lasso selection is a very important feature. Instead of requiring the user to understand that they must click on the little lasso icon (it’s not 100% intuitive for non plotly users, it’s small, and it only shows up on hover), I would like to have a button outside the plot and have some logic that when the button is clicked, the lasso selection would be set.

I figured out I can do it with javascript but finding the icon’s HTML element and simulating a click on it, for example

$("#myplot .modebar .modebar-btn[data-val='lasso']")[0].click()

But I wanted to know if there’s a more proper way to do it?

Yes

Plotly.relayout(graphDiv, 'dragmode', 'lasso')
1 Like

Awesome that works, thanks!