Hi all,
I tried googling a bit for this one but with little success, although the issue might be quite simple to solve. I have the following Dropdown:
dcc.Dropdown(
id = 'su-dropdown',
multi = True,
placeholder = 'Select supplier(s)',
options = [])
Which the use can use to choose from a list of suppliers. The options in the list depend on other variables that are passed from other elements. So, I wanted to write the following callback
app.callback([dash.dependencies.Output('su-dropdown', 'options')],
[dash.dependencies.Input('dataload-dropdown', 'value'),
dash.dependencies.Input('datepick-range', 'start_date'),
dash.dependencies.Input('datepick-range', 'end_date')]
)
def update_su_options(value, start_date, end_date):
# there might be a better way to do this, but for now I got this to work
# also because default values from the date picker don't get automatically passed unless user
# chooses dates themself
if (value is None) or (start_date is None) or (end_date is None):
raise PreventUpdate
else:
#value picks dataset
df = dataset_dict[value]
option_list : List[Dict[str,str]] = []
# filter by dates passed into callback
option_df = df[(df.Date >= start_date) & (df.Date < end_date)]
# clean and reformat to mach [{'label' : label, 'value' : value}] spec of option prop
option_list = option_df[['SupplierName','SupplierID']].\
drop_duplicates().\
rename(columns = {'SupplierName' : 'label',
'SupplierID' : 'value'}).\
dropna().to_dict('records')
# TODO: fix this return
return option_list
Now the app raises callback errors saying it expected only 1 variable to be returned, not len(option_list)
. When I print the list to the console, however, it looks like what I would specify manually. Does anyone here know how I could make this work or if there’s a better way to do this?