ibenok
November 22, 2022, 1:01pm
1
I have a function that auto scales the y axis. It takes in the figure and relayout data objects and then spits out a y axis that fits some criteria that I pre-determined. I want to add a new modbar button in dash plotly on python that fires the function and updates the figure any time I click on it. Is that possible?
It looks like this same question came up two years ago but there was no answer Custom modeBar Buttons in Python
To my knowledge, you can’t add custom modebar buttons through python. You can in plotly.Js.
You can add a button to the modebar in JavaScript with a clientside_callback, but again, it is a JavaScript interaction.
ibenok
November 22, 2022, 5:14pm
3
Can I add the javascript to the main.js file? I have other javascript in there that interacts with my plotly python dashboard
Yes, you can. But it might be easier to implement with a clientside callback.
ibenok
November 22, 2022, 5:17pm
5
Hmm… I’m not sure what you mean. Can I add a callback that’s attached to the modbar button? I’d just like to get rid of the autoresize part of the button
Take a look at this post, in it I add a custom button to the modebar group whenever the page loads or there is an update to the dash components.
Hello @popo ,
It took me some time, but I finally got something I think you’ll be happy with. You can polish it however you want to, this is just a rough showing.
[dragging-subplots]
All of this is done on the client side, however… You can use the clientside to chain a callback to the server, easily.
Here is the .js file:
function coolEffects() {
$(".modebar-group:first-of-type").prepend($('<button onclick=toggleEdit(this)>Testing</button>'))
}
var sp;
var oldDom;
fu…
But, you could instead use a clientside_callback to add the button upon the dcc.Graph populating.
At that point, you can design the button to look however you want to.