Using a dict()
instead of go.Layout
doesn’t help much. It is still the same. I’ll try to create a toy example of this scenario.
In the mean time, here is the code I have:
@app.callback(Output('by-tc_container', 'children'),
[Input('by-tc_container', 'id'),
Input('ver-dropdown', 'value'),
Input('dropdown1', 'value'),
Input('metric-dropdown', 'value')])
def display_graphs(id, version, ip, metric):
df_steadystate = get_steady_state_data(version, ip)
graphs = []
if not df_steadystate.empty:
# t0 = time.time()
cases_sorted = df_steadystate.caseid.sort_values()
# t1 = time.time()
# print("Time taken to sort df: {}".format(t1-t0))
t0 = time.time()
for case in cases_sorted:
data = []
# t0_filtered = time.time()
df_filtered = df_steadystate.loc[df_steadystate.caseid == case]
# t1_filtered = time.time()
# print("Time for filtering: {}".format(t1_filtered-t0_filtered))
# t0_scatter = time.time()
plot_data = go.Scatter(
x=df_filtered['runid'],
y=df_filtered[metric],
mode='lines+markers',
name=testcase,
hoverinfo='y',
line=dict(
shape='spline'
)
)
data.append(plot_data)
# t1_scatter = time.time()
# print("Time for scatter: {}".format(t1_scatter-t0_scatter))
layout = dict(
title = testcase,
titlefont=dict(
size=28,
),
xaxis=dict(
title='Versions',
showticklabels=True,
type='category',
exponentformat='none',
showexponent='all',
categoryorder='category ascending'
),
yaxis=dict(
title = metric,
showticklabels=True,
tickangle=45,
exponentformat='none',
showexponent='none'
),
legend=dict(
y=0.5,
traceorder='reversed',
font=dict(
size=16
)
),
hovermode='closest',
)
t0_graph_append = time.time()
graphs.append(html.P([
dcc.Graph(
id='graph-{}'.format(case),
figure={
'data': data,
'layout': layout
}
),
html.Br()
]))
t1_graph_append = time.time()
print("Time taken for graph append: {:.8f}".format(t1_graph_append-t0_graph_append))
t1 = time.time()
print("Time taken for for-loop: {:.2f}".format(t1-t0))
return html.Div(graphs)
And this is part of the main layout which are used as inputs and outputs for the callback:
html.Div(id='by-tc_container'),
html.Div(dcc.Graph(id='empty', figure={'data': []}), style={'display': 'none'}),