Input and Storage in constant loop

Hi guys,

I’m stuck on developing my filter button. I have multiple Inputs (dropdowns) and a filter button (and also a reset button (but thats not important for now). The problem I’m having is that my filter button updates my storage. And because my storage is updated the callback is called and therefore the filter is activated again. I tried using a counter for n_clicks, unfortunately that didn’t work. I also tried resetting n_clicks to None, but that didn’t work either.

Can you guys help me with a solution?

Below part of my code (second part is most important):

`@app.callback(Output(‘local’, ‘data’),
[Input(‘cld_accountgroup1_dropdown’, ‘value’),Input(‘cld_company1_dropdown’, ‘value’),Input(‘cld_stars1_dropdown’, ‘value’),Input(‘cld_object1_dropdown’, ‘value’),Input(‘filter1’, ‘n_clicks’),Input(‘reset_filter1’, ‘n_clicks’)],
[State(‘local’, ‘data’)])

def store(accountgroup,bedrijf,sterren,Object,n_clicks,filter1,data):
if filter1:
df_all = pd.read_sql(df, engine)
data = df_all
data = data.to_json()

return data

if n_clicks:
if type(data) == str:
data = json.loads(data)
data = pd.DataFrame(data)
df_all = data

if bedrijf is not None and accountgroup is None and sterren is None and Object is not None:
print(‘Cascade 2’)
data = df_all[(df_all[‘Concurrent’] == bedrijf) & (df_all[‘Hotelnaam’] == Object)]

return data`

Thanks in advance

Sounds like callback_context may help you - to let your callback know which particular input changed to trigger it. See, scroll to: How do I determine which Input has changed?

I’m going to give that a try and will let you know. I didn’t knew that existed. Thanks.

Hi @alexcjohnson,

I fixed the issue with your advice. Thanks for the help! I really appreciate it.

1 Like