I am quite new to programming and to plotly dash as well. I have some tabs in my dashboard and in each tab among other things i have a text input box (int) and a button that triggers some calculations using the input.
With the following script, when I select the tab, the callback is triggered and the calculation already starts with the empty value in the text, even before I click the button. I have an if clause to return nothing when the text input box is empty. But that doesn’t seem to be working. It directly goes to the final “else” clause. How can i solve this? Thank you!
@app.callback(Output('PRINTOUTPUT', 'children'),
[Input('create_button', 'n_clicks'),
Input('selection_tabs', 'value')],
[State('text-input', 'value')])
def xyz (clicks, selected_tab, textinput):
changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0] #To determine if n_clicks is changed.
if 'create_button' not in changed_id:
return ""
elif 'create_button' in changed_id:
if textinput =="": #Do nothing if button is clicked and input num is blank.
return "No input"
else:
#Do some calculations based on the selected tab and input
return "Successful"