Hi,
I have a sceneria like this:
I have 5 different dropdowns and every of them selecting binary options. You can take this as:
after this 5 input/dropdown selection I click a button, then smth happens.
My problem is: Every dropdown selection triggers the function.
I wanna select 5 dropdown options. Anter after I TRIGGER THE FUNCTION IF AND ONLY IF I CLICK THE BUTTON, but it triggers after every dropdown selection.
How can I solve this problem??
You can check out the last example on this page Basic Callbacks | Dash for Python Documentation | Plotly where you store the state of the button. Once n_click is changed to one, you can then perform the action that you would want to do like seeing an update of your graph.
1 Like
I solved my problem with this:
class Trigger:
def __init__(self, n_click_):
self.n_click_ = n_click_
def ifTrigger_(self, n_clickNEW):
if ((self.n_click_ != n_clickNEW) & (n_clickNEW == 0)):
ifTrigger = False
self.n_click_ = 0
elif (self.n_click_ != n_clickNEW):
self.n_click_ = n_clickNEW
ifTrigger = True
else:
ifTrigger = False
return ifTrigger
button_ = Trigger(0)
I run this class begining of the page and after thisline i initiate it with:
button_ = Trigger(0)
and after this in the Callback function i used this:
def modelOzetiYazma(x1 ,x2 ,x3 ,x4 ,x5 , n_click_):
didChange_= button_.ifTrigger_(n_click_)
if (didChange_):
print(' Now it is doing what i want')
return x,y,z,d
return None, None, None, 0
NOTE: There is 3 different if clause bc:
-
first one for: If i use it several times and after this I refreshed the page. Bc when i refresh the page n_clickNEW is turning 0 again and I should force with this problem. It should not trigger the function.
-
second one for: If nclick change or not?
-
third one is for: If there is no change in nclick but other.