cody
July 9, 2021, 9:54am
1
Hi Dash Community,
when using multiple outputs in a callback, I got a callback error message saying Expected the output type to be a list or tuple but got: Graph
.
@app.callback(Output('div_top', 'children'),
Output('div_bottom', 'children'),
Input('file-select', 'value'),
Input('slider', 'value')),
def update_graph(file, value):
graph = get_graph(file, value)
cur_value = value
return graph, cur_value
graph
is of type dcc.Graph
and value
is an integer.
I think I have a syntax error here, but I can’t get my head around it. My Output is defined in a tuple, so are my return values. So what did I miss here?
Thank you so much for your help!
Hi @cody ,
I don’t think you can return a dcc.Graph
to a children of a div. Use the component id of dcc.Graph
from your layout and return to the component property figure
.
Something like this:
@app.callback(Output('my-graph', 'figure'),
Output('div_bottom', 'children'),
Input('file-select', 'value'),
Input('slider', 'value')),
def update_graph(file, value):
graph = get_graph(file, value)
cur_value = value
return graph, cur_value
cody
July 9, 2021, 12:19pm
3
Hi @atharvakatre
thank you for your reply. Before adding the second Output, I could return a dcc.Graph
to a children of a div.
Anyway I used a dcc.Graph
component and returned figure
to that component, but I still got the same error.
cody
July 9, 2021, 12:36pm
4
OMG, I feel so stupid. I have a second return in an if statement in my callback and forgot to define the return value for the second output there!
Unlike Inputs, all Outputs need to be addressed in every return statement!
@app.callback(Output('div_top', 'children'),
Output('div_bottom', 'children'),
Input('file-select', 'value'),
Input('slider', 'value'),
Input('choice', 'value'),
def update_graph(file, value, choice):
if choice == 0:
graph = get_graph(file, value)
cur_value = value
return graph, cur_value # Attention!
elif choice == 1:
graph = get_graph(file, value**3)
cur_value = value**3
return graph, cur_value # Attention!