Hi there, I’m trying to append a seasonality graph per unique Finished Good. It works when I use 1 item code however when I try and append multiple unqiue items to the html.Div called seasonal-chart it wont dislay.
I was using this How to plot multiple graphs/plots in a for loop in a Dash app? - #9 by vivekvs1 as a refernece but am unable to make it work in my case.
Let me know if there is any additional info i can provide
@callback(
Output('indicator-graphic', 'figure'),
Output('Datatable2', 'children'),
Output('indicator-graphic2', 'figure'),
Output('seasonal-chart', 'children'),
Input("dataTable", "selected_rows")
)
...
...
...
FGgoodsSeason = FGgoods.reset_index()
graphList = []
for product in FGgoodsSeason.Trunc.unique():
DFPointer2 = FGgoodsSeason.query("Trunc == @product").set_index('TrnDate')
for modelcol in ['multiplicative', 'additive']:
try:
# Multiplicative Decomposition
print(f"\tTrying {modelcol} decomposition with extrapolate_trend\n")
Eresult_mul = seasonal_decompose(DFPointer2['Monthly Total Sales CAD'], model=modelcol, extrapolate_trend='freq', period = int(len(DFPointer2)/2))
Efig = make_subplots(
rows=4, cols=1,
subplot_titles=["Observed", "Trend", "Seasonal", "Residuals"],
shared_xaxes=True)
Efig.add_trace(
go.Scatter(x=Eresult_mul.seasonal.index, y=Eresult_mul.observed, mode='lines'),
row=1, col=1 )
Efig.add_trace(
go.Scatter(x=Eresult_mul.trend.index, y=Eresult_mul.trend, mode='lines'),
row=2, col=1 )
Efig.add_trace(
go.Scatter(x=Eresult_mul.seasonal.index, y=Eresult_mul.seasonal, mode='lines+markers'),
row=3, col=1 )
Efig.add_trace(
go.Scatter(x=Eresult_mul.resid.index, y=Eresult_mul.resid, mode='markers'),
row=4, col=1 )
Efig.update_layout(height=800, title_text=" ".join(["Extrapolate trend", modelcol.capitalize(), "model for", product]), margin=dict(t=100), title_x=0.5, showlegend=False)
print('\n')
graphList.append(html.Div(dcc.Graph(Efig, id=f'graph-{product}-{modelcol}')))
except:
print(f"\t\t{modelcol} decomposition with extrapolate_trend on {product} FAILED!\n")
graphList.append(Efig.add_annotation(text="No Data", showarrow=False, font=dict(size=30)))
continue