1

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])
3
  • I believe your problem is in return {}, {}. You should return only one dict here. Commented Jul 20, 2020 at 13:53
  • Thank you @DanielR that worked. If you want to comment this answer, I can mark it as the correct solution. Commented Jul 20, 2020 at 14:05
  • Ok, will do that. Commented Jul 20, 2020 at 14:06

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.