# Plotly Dash becomes unresponsive when adding a callback for dcc.Graph

**URL:** <https://community.plotly.com/t/plotly-dash-becomes-unresponsive-when-adding-a-callback-for-dcc-graph/83751>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [April 12, 2024, 8:55pm UTC](https://community.plotly.com/t/plotly-dash-becomes-unresponsive-when-adding-a-callback-for-dcc-graph/83751 "2024-04-12T20:55:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anastasia.m](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/anastasia.m/32/27691_2.png) [@anastasia.m](https://community.plotly.com/u/anastasia.m)\
**Post date:** [April 12, 2024, 8:55pm UTC](https://community.plotly.com/t/plotly-dash-becomes-unresponsive-when-adding-a-callback-for-dcc-graph/83751/1 "2024-04-12T20:55:35Z")

</div>

Hi!

I’m using dash version 2.16.1 and am currently having an issue that I can’t seem to find an explanation or a solution for. I have an application built mostly with elements from dash mantine components with multiple tabs that perform different experiments with Large Language Models. Everything runs smoothly, my dataset isn’t very large, and any calculations are performed quite fast. However, when I try to add a dcc.Graph element into the dashboard and then add a callback for it my app becomes unresponsive, when I reload it it just says “Loading” until it finally times out and crashes with no errors on the back end. Adding dcc.Graph itself into the layout doesn’t cause any issues, but creating a callback for it is what makes it go unresponsive. I’ve updated all the versions of libraries I’m using, I’ve tried moving the graph object outside of the dmc stack, I’ve experimented with the contents of the callback, but no matter if the callback function is empty, returns an empty graph, or if I actually load the data and generate the correct graph, the result is always the same - an unresponsive application. I’m not sure if I’m simply missing something or not realising something very obvious, or if it’s a bug, but I would appreciate any help and advice!

Here is how my graph is added to the stack:

```auto
body_stats_chat = dmc.Stack(
    [
        html.Br(),
        dmc.Textarea(
            label="Enter your question:",
            id="question-text-stats",
            style={"width": 1350, "align": "center"},
            autosize=True,
            minRows=4,
        ),
        dmc.Button(
            "Submit",
            id="submit-btn-stats",
            leftIcon=DashIconify(icon="arcticons:openai-chatgpt"),
            style={"width": 1350, "align": "center"},
            color="blue",
        ),
        dcc.Loading(
            id="loading-answer-stats",
            type="dot",
            children=[
                html.H5(id="answer-label-stats"),
                html.Div(id="answer-text-stats"),
                html.Div(id="answer-table-stats"),
                dcc.Graph(id="stats-graph"),
                html.Br(),
            ],
            style={"width": 1350, "align": "left"},
        ),
        html.Br(),
    ]
)

```

And here is the structure of a callback I’m using:

```auto
@callback(
    Output('stats-graph', 'figure'),
    Input('question-text-viz', 'value'),
    Input('submit-btn-viz', 'n_clicks'))
def get_viz_answer(question, submit_btn):
    global answers, current_answer
    changed_ids = [p['prop_id'].split('.')[0]
                   for p in dash.callback_context.triggered]
    button_pressed = 'submit-btn-viz' in changed_ids
    if not button_pressed:
        return None
    df = pd.read_csv('data.csv')
    fig = px.bar(df, x="topic", y="value")
    return fig

```

Thank you!

---

<div class="post-metadata">

**Author:** ![davidharris](https://avatars.discourse-cdn.com/v4/letter/d/df705f/32.png) [@davidharris](https://community.plotly.com/u/davidharris)\
**Post date:** [April 13, 2024, 12:22pm UTC](https://community.plotly.com/t/plotly-dash-becomes-unresponsive-when-adding-a-callback-for-dcc-graph/83751/2 "2024-04-13T12:22:31Z")

</div>

Just needs a couple of small changes.

1. Change IDs in callback so they correspond with IDs in layout
2. return _no\_update_ not _None_ from the callback when _not button\_pressed_. For some reason I don’t understand, returning _None_ just once (it happens on load) seems to stop the callback working on subsequent calls. (Or you could use _State(‘question-text-viz’, ‘value’)_ rather than _Input(…)_ if you want to take no action when it changes)

---

<div class="post-metadata">

**Author:** ![anastasia.m](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/anastasia.m/32/27691_2.png) [@anastasia.m](https://community.plotly.com/u/anastasia.m)\
**Post date:** [April 14, 2024, 2:52am UTC](https://community.plotly.com/t/plotly-dash-becomes-unresponsive-when-adding-a-callback-for-dcc-graph/83751/3 "2024-04-14T02:52:59Z")

</div>

Thank you!

1. Sorry this was a typo on my end, the IDs do actually match. But thank you for pointing that out, that would’ve definitely caused an issue.
2. This helped, thank you so much! I usually return _None_ for _not button\_pressed_ instances and never had this issue before so this is very odd but so helpful to know. Thank you!!
