Callback output as a figure

@adamschroeder
Please correct me If I am wrong
I saw an issue, please observe the following code

@callback(Output(‘decomposed_graphs_tsa’, ‘figure’),
[Input(‘gen_decomposed_graphs_tsa’, ‘n_clicks’),
State(‘df_columns_dropdown_label_tsa’, ‘value’),
State(‘df_columns_dropdown_date_tsa’, ‘value’), ],
prevent_initial_call=True)
def update_graph(n_clicks, df_columns_dropdown_label_tsa, df_columns_dropdown_date_tsa):
print(df)

fig_seasonality_decompose = decomposition_tsa(df, df_columns_dropdown_label_tsa, df_columns_dropdown_date_tsa)

return fig_seasonality_decompose

I have one output, as a graph, I put a square bracket around this single output unintentionally, and when I run the code there was an error that
“Expected class tuple or str list but received Plotly go figure”

My question is that why is it so?
It was always my practice to put even single output in square brackets. It took a long for me to remove the brackets and it worked as I did not think about it.

Hi @SaadKhan ,

formatted your code for you.

Could you explain what exactly is the problem you are facing?

@callback(
    Output(‘decomposed_graphs_tsa’, ‘figure’),
    [
        Input(‘gen_decomposed_graphs_tsa’, ‘n_clicks’),
        State(‘df_columns_dropdown_label_tsa’, ‘value’),
        State(‘df_columns_dropdown_date_tsa’, ‘value’),
    ],
    prevent_initial_call=True
)
def update_graph(n_clicks, df_columns_dropdown_label_tsa, df_columns_dropdown_date_tsa):
    print(df)
    fig_seasonality_decompose = decomposition_tsa(df, df_columns_dropdown_label_tsa, df_columns_dropdown_date_tsa)

return fig_seasonality_decompose
1 Like

change this “Output(‘decomposed_graphs_tsa’, ‘figure’),” with "[Output(‘decomposed_graphs_tsa’, ‘figure’),]
gves error as stated above

If you do so, you have to return a list:

return [fig_seasonality_decompose]

1 Like

okay Thank you