✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

How to add dcc.Graph dynamically?

I want to add a dcc.Graph to my Dash app only if there is data available to plot in the graph. If this is not the case I’d like to hide the dcc.Graph.

return a div without the graph from the callback as children

app.callback(Output('my-div', 'children'), [Input('some_input', 'some_value')]):
def get_graph(value):
    # check if it should display graph or not, return True/False
    if condition:
       return html.Div(dcc.Graph(figure=figure))
    else:
       return html.Div('no data to plot')
1 Like