I generate similar graphs with their own RadioItem using different ids, and put in layout within one html div. I want to update them using the ratio selector callback separately, but these callbacks are the exact same functions just with different output/input ids. I am doing them in list of graphs together, but this is extremely slow… I have also tried to wrote separate callback functions, but this approach is very redundant. Is there any other options?
def get_selector_graph_combo(data, app, day_range):
return [get_time_selector(app), get_app_graph(data, app, day_range=day_range)]
def get_time_selector(app):
selector_id = app + '_date_range'
return dcc.RadioItems(id=selector_id,
options=[{'label': '30', 'value': 30},
{'label': '60', 'value': 60},
{'label': '90', 'value': 90}],
value=30)
def get_app_graph(data, app, day_range=30):
return dcc.Graph(id=app, figure=get_app_fig(data, app, day_range=day_range))
def construct_html_children(data, app_list=APP_LIST):
selector_graph_combos = []
for (app_name, bundle_id) in app_list:
combo = get_selector_graph_combo(data, app_name, day_range=30)
selector_graph_combos.extend(combo)
return selector_graph_combos
app_combo_list = construct_html_children(data)
app.layout = html.Div([
dcc.Markdown('''
#
## Products Dashboard
#
'''),
html.Div(app_combo_list)
])
output_list = [Output(id[0], 'figure') for id in APP_LIST]
input_list = [Input(id[0]+'_date_range', 'value') for id in APP_LIST]
@app.callback(output_list, input_list)
def update_date_range(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16):
day_range_list = [d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16]
graphs = [get_app_fig(data, app_name, day_range)
for (day_range, (app_name, bundle_id))
in zip(day_range_list, APP_LIST)]
return graphs