Skip to content
Advertisement

Reverse a Bokeh Button operation by clicking the button again

I have a vision for a dashboard where you can click on one of several Buttons to perform additive operations, and undo the operation by clicking on the button again. Actually undo is the wrong word, as I do not want the second click to restore it to an original state as that could interfere with the results of another button, but I would like the second click to take out what it put in. As an example I have the following problem where pushing a button labeled Apple, adds a value of 3.0 to every data point, which updates the plot of circle glyphs. My question is this, “is there a way I can set up the code where pressing the button again will subtract a value of 3.0?”

JavaScript

Advertisement

Answer

One possible solution is to add a second CDS to your custom JavaScript to count the clicks.

JavaScript

In you JavaScript you have to add a few lines. If the number of clicks is even, you add f, else you substract it.

JavaScript

The created figure will work like this:

toggle

Complete code

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement