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

Graph is Empty - Unable to produce Scatterplot

Both first_selector and second_selector are the ids of Dropdowns which are assigned starter values. I would expect the plot to be populated upon running the app, but nothing I do can seem to get data into the graph.

I’ve checked my filter_dataframe function is working properly as well.

Even inserting simple lists for x and y do not work within make_main_figure() - I tried putting in x = [1,2,3], y = [4,5,6] and the plot is still blank as in my attached image.

@app.callback(Output('main_scatter_plot', 'figure'),
              [Input('first_selector', 'value'),
               Input('second_selector', 'value')])
def make_main_figure(first_selector, second_selector):

    dff = filter_dataframe(DF, first_selector, second_selector)
    traces = []
    for value in dff['Number'].unique():
       df_by_result = dff[dff['Number'] == value]
        traces.append(go.Scatter(
            x = df_by_result['Metric_1'],
            y = df_by_result['Metric_2'],
            more = 'markers',
            opacity = 0.7,
            marker = {'size': 15},
            name = result
    ))
 
    return {'data': [traces], 'layout': go.Layout(title='My Plot',
                                                xaxis = {'title': 'Metric_1', 'type': 'linear'},
                                                yaxis = {'title': 'Metric_2', 'type': 'linear'}
                                                )}

First I would try removing the brackets around traces, since you are already generating a list, it is a list of lists containing scatter objects when it should be a 1D list if I am understanding it correctly.

If that does not work…

I would guess that you are combining the object go.Scatter type syntax with the json/dict syntax. If you are using go.Scatter, then you should be using go.Figure(data=traces, layout=go.Layout(…)).