I’m having trouble with this one callback, which usually returns “Error loading dependencies” despite the function working perfectly when isolated in a separate cell. I am new to Dash, but under the impression that “Error loading dependencies” only came up when the number of inputs/outputs in the callback and the function do not match.
In summary, I want to create a hidden Div that stores an index from a dataframe, then return that row’s other variables later. Any ideas to update this dynamically??
In the DOM:
html.Div(id=‘sample-index’,
style={‘display’:‘none’})
In callbacks:
@app.callback([Output(‘sample-index’, ‘children’)],
[Input(‘generate-button’, ‘n_clicks’)],
[State(‘first-dropdown’, ‘value’),
State(‘SliderA’, ‘value’),
State(‘second-dropdown’, ‘value’),
State(‘SliderB’, ‘value’),
State(‘third-dropdown’, ‘value’),
State(‘mini-dropdown’, ‘value’)]
)
def find_sample(n_clicks, feat1, val1, feat2, val2, feat3, val3):
if n_clicks is None:
return “Choose your index”
#Find 1000 indices closest to specified feature 1 value
first_search=df.iloc[(df[feat1]-val1).abs().argsort()[:1000]]
#Narrow down options to 100 with values closest to 2nd feature value
second_search=first_search.iloc[(first_search[feat2]-val2).abs().argsort()[:100]].reset_index()
#Narrow to options with categorical match
final=second_search.loc[second_search[feat3]==val3][:1]
#Check whether categorical variable match was found
if len(final)==1:
return [final[‘index’]],
#Else return best combo of first two variables
else:
return [second_search.iloc[0][‘index’]]