Black Lives Matter. Please consider donating to Black Girls Code today.

Dash - Bar graphs - 2 Inputs ClickData - 2 clicks required

Hi, I wonder if anyone could help me with this issue.

I have 2 bar graphs.

When I click Graph 1:

  • it changes the color of the bar clicked in graph 1
  • it changes the data of Graph 2

When i click Graph 2:

  • it changes the color of the bar clicked in graph 2

(this is a simplification of wider dashboard)

The callback for the Graph 2 is this one:

    Output('graph_2', 'figure'),
    [Input('graph_1', 'clickData'),
     Input('graph_2', 'clickData')])
def change_graph2(click_g1, click_g2):
    y = click_g1['points'][0]['x']
    x = click_g2['points'][0]['pointIndex']
    return upgrade_g2(y, x)

When the app is opened, if graph 1 is clicked, graph 2 doesn’t refresh, not until the graph2 is clicked at least once. After that, clicking on graph 1 refreshes graph 2.

The weird thing is that, when the app is opened, if i click graph 2 without having clicked graph1, the appcallback for graph2 works…

I would thank anyone that can help me
David Rowie