Created
January 2, 2022 04:36
-
-
Save shkiefer/94b6e7baa9075766f710dab9d1ec28ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.callback( | |
Output(f'{APP_ID}_example_tf_dropdown', 'options'), | |
Output(f'{APP_ID}_example_tf_dropdown', 'value'), | |
Output(f'{APP_ID}_example_result_dropdown','options'), | |
Output(f'{APP_ID}_example_result_dropdown','value'), | |
Input(f'{APP_ID}_example_dropdown', 'value') | |
) | |
def dash_vtk_update_result_options(example_name): | |
ctx = dash.callback_context | |
if not ctx.triggered: | |
raise PreventUpdate | |
model = dpf.Model(EXAMPLE_MAP[example_name]) | |
result_info = model.metadata.result_info | |
res_options = [{'label': res.name, 'value': res.name} for res in result_info.available_results] | |
tf = model.metadata.time_freq_support.time_frequencies.data | |
tf_options = [{'label': tfi, 'value': i} for i, tfi in enumerate(tf)] | |
return tf_options, len(tf)-1, res_options, result_info.available_results[0].name | |
@app.callback( | |
Output(f'{APP_ID}_example_comp_dropdown','options'), | |
Output(f'{APP_ID}_example_comp_dropdown','value'), | |
Output(f'{APP_ID}_example_comp_dropdown','disabled'), | |
Input(f'{APP_ID}_example_result_dropdown','value'), | |
State(f'{APP_ID}_example_dropdown', 'value') | |
) | |
def dash_vtk_update_comp_options(res_name, example_name): | |
ctx = dash.callback_context | |
if not ctx.triggered: | |
raise PreventUpdate | |
model = dpf.Model(EXAMPLE_MAP[example_name]) | |
result_info = model.metadata.result_info | |
res = next((r for r in result_info.available_results if r.name == res_name), None) | |
if res is not None: | |
if res.n_components == 1: | |
comp_options = [{'label': 0, 'value': 0}] | |
comp_value = 0 | |
comp_disabled = True | |
else: | |
comp_options = [{'label': i, 'value': i} for i in range(res.n_components)] | |
comp_value = 0 | |
comp_disabled = False | |
return comp_options, comp_value, comp_disabled | |
else: | |
raise PreventUpdate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment