Once the button is pressed, the n_clicks would increase to 1.
I’m using Input("button_ID1", "n_clicks") in my callbacks. But, then I want to reset the n_clicks to zero as if it’s an On-Off button.
Thanks in advance.
Hi @essi1990, just check whether n_clicks is odd or even:
@app.callcakck(
Output("some-component", "property"),
[Input("button_ID1", "n_clicks")]
)
def on_off(n):
if not n or n % 2 == 0:
#Action when OFF
else:
#Action when ON
@RenaudLN Thanks for your prompt answer. This probably will result in strange behavior since it’s dependent on the actual number of clicks.
However, I like your implementation since it does not require outputting n_clicks property. I have to think more about the implementation though
Another way I’m thinking is to use BooleanSwitch or PowerButton from Dash DAQ, and change their styles to be rectangular with some text just like the regular html.Button. I believe changing the style of PowerButton/BooleanSwitch is possible. I just need to research that.