Peyman
December 5, 2022, 7:52pm
21
Sorry Bryan,
I have a question here. when I used the callback_context to use one component id as an output multiple times, how I can have another output? For example, in this part of my code, I want to get df_min_json as an output as well and store it in a new dcc.Store(id=‘table_min_slice’)
def update_with_rangeslider(js_df, feature, ranges):
if (feature is None) or (ranges == []):
return dash.no_update
else:
print(ranges)
dff = pd.read_json(js_df, orient='split')
df_sliced_min = dff[(dff[feature] < ranges[0])]
df_min_json = df_sliced_min.to_json(date_format='iso', orient='split')
.
.
.
What do you mean by json?
If you do df_min_json.to_dict('records') it will be a json dictionary.
Peyman
December 5, 2022, 7:59pm
23
like the thing I did here in my code:
def store_df(chosen_dataset):
if chosen_dataset is None:
return dash.no_update
else:
df = pd.read_csv(path + chosen_dataset + '.csv')
df_json = df.to_json(date_format='iso', orient='split')
return df_json
You can return the dfs you want from the function by using comma’s.
return fig, df_json,..
Peyman
December 5, 2022, 8:15pm
25
but in here, I have introduced only one output, and when I add multiple outputs, everything mess up.
@app.callback(
Output('graph3', 'figure'),
Input('dropdown1', 'value'),
Input('my_rangeslider', 'value'),
Input('table1', 'data'),
Input('dropdown2', 'value'),
prevent_initial_call=True
)
def group1(b1, b2, js_df, feature):
)
Having multiple outputs does add complexity.
But, just remember, when you add an output, all of your returns have to have that additional output, and you should be fine.
Peyman
December 5, 2022, 8:19pm
27
Thank you very very much.