Hi,
How to restrict the user must click the “search” button to display the new data in the report?
For example,
there has year-dropdown, month-dropdown and date-dropdown. All the value is immediately show the latest value according to the list.
The report to be shown based on the selected value, the user will need to click the search button.
However, when the user change the dropdown value, the report will immediately reflect based on the new selected value.
Expect the search button must be clicked every time when new value selected.
code.py
@callback(
Output('month_dd','options'),
Input('year_dd', 'value')
)
def update_dd (year_dd):
year_month= df.drop_duplicates(['mthyr'], inplace= False)
relevant_month= year_month[ df['year'] == year_dd]['monthname'].values.tolist()
month_option= [dict(label=x,value=x)for x in relevant_month]
return month_option
@callback(
Output('month_dd','value'),
Input('month_dd', 'options')
)
def default_value(latest_month):
month_value = latest_month[-1]['value']
return month_value
# #date dropdown based on filtered month
@callback(
Output('_date_dd','options'),
Input('month_dd', 'value'),
State('year_dd', 'value')
)
def update_dd (month_dd, year_dd):
month_date= df.drop_duplicates([Date'], inplace= False)
relevant_date= month_date[ (df['monthname'] == month_dd) & (df['year'] == year_dd) ]['Date'].values.tolist()
date_option= [dict(label=x,value=x)for x in relevant_date]
return date_option
@callback(
Output('date_dd','value'),
Input('date_dd', 'options')
)
def default_value(latest_date):
date_value = latest_date[-1]['value']
return date_value
@callback(
Output('storedate','data'),
Input('-search-button', 'n_clicks'),
State('date_dd', 'value'),
State('year_dd', 'value'),
State('month_dd', 'value'),
)
def stored_selected_value (n_clicks, date, year, month):
ctx = callback_context
if not ctx.triggered_id or 'search-button' not in ctx.triggered_id:
raise dash.exceptions.PreventUpdate
return {'date': date, 'year': year, 'month': month}
‘content.py’
@callback(
Output('content', 'children'),
Input('search-button', 'n_clicks'),
prevent_initial_call=True
)
def update_analysis_table(n_clicks):
if n_clicks > 0:
return combine
else:
return []