sshah98
sshah98

Reputation: 352

Getting an error with Dash Python -- Invalid argument `figure` passed into Graph with ID "graph". Expected `object`. Was supplied type `array`

I have checked the other similar questions related to the error I am facing. I cannot seem to see why I have been consistently getting this error:

Invalid argument `figure` passed into Graph with ID "graph".
Expected `object`.
Was supplied type `array`.
Value provided: 
[
  {},
  {}
]

This is the following code for the figure I want to update. Essentially, there is a dropdown with a list of names, and the graph should update to the new figure with the topics related to the dropdown value selected.


# main component of dashboard
BODY = dbc.Container(
    [

        dcc.Dropdown(
            id='xaxis-column',
            options=[{'label': i, 'value': i}
                     for i in sorted(user_list['displayName'].unique())],
        ),
        dbc.Card(dcc.Graph(id="graph")),
      
    ], className="mt-12")


@app.callback(
    Output('graph', 'figure'),
    [Input('xaxis-column', 'value')]
)
def update_graph(xaxis_column_name):

    print(xaxis_column_name)

    df = pd.json_normalize(dataframe['user'])
    df['parsedMessage'] = dataframe['parsedMessage']
    df['timestamp'] = dataframe['timestamp']
    df_one_user = df['displayName'] == xaxis_column_name

    dff = df[df_one_user]

    messages = list(
        dff["parsedMessage"].dropna().values)

    if len(messages) < 1:
        return {}, {}

    text = " ".join(list(messages))

    stop_words = ['will', 'reply', 'think', 'http',
                  'https', 'in reply', 'the us', 'us', 'now'] + list(STOPWORDS)

    wc = WordCloud(stopwords=stop_words, max_words=25, max_font_size=80)
    wc.generate(text)

    word_list, freq_list, fontsize_list, position_list, orientation_list, color_list = [
    ], [], [], [], [], []

    for (word, freq), fontsize, position, orientation, color in wc.layout_:
        word_list.append(word)
        freq_list.append(freq)

    word_list_top = word_list[:10]
    freq_list_top = freq_list[:10]

    word_df = pd.DataFrame(
        {'word_list': word_list_top,
         'freq_list': freq_list_top,
         })
    # print(word_df)

    fig = px.bar(word_df, x='word_list', y='freq_list')

    return fig

if I don't do the callback, and just hardcode a value for the xaxis_column_name, then it works.

This is my app layout:

app.layout = html.Div(children=[NAVBAR, html.Br(className="my-2"), BODY])

Upvotes: 1

Views: 1442

Answers (1)

Daniel R
Daniel R

Reputation: 2042

I believe your problem is in return {}, {}. You should return only one dict here.

Upvotes: 1

Related Questions