Callback Error when updating dcc.graph

Hi team!

Just wanted to say that Dash is an amazing piece of work and is something that I really want to master well. I’m currently working to build a mini app which fetches stock prices via API and plots it.

I included the code to plot the graph, relevant area of the layout as well as the piece of code i use to fetch the data via api.

The dash app is running locally!

Layout

app.layout = html.Div(
    id = "full-page",
    children=[
        html.H1(children="Regressing Stock Prices"),
        html.Div( id ="stock-code-div", children = 
            [html.Span(
                dcc.Dropdown(id = "input-stock",value = "AAPL", options = stock_list, style = {"width":"50%","padding-bottom":"20px"})
                    )
                ]),
                
        html.Div( id = "stock-chart-div", children = 
            [
            html.Span(id = "stock-chart-span",children =dcc.Loading(
                    children = dcc.Graph(id ="stock-chart",config={"scrollZoom":True,"responsive":True,"showAxisDragHandles":True},style ={"width":"60%"})
                            )
                       ),
            ]),
        html.H2(children = "News"),
        html.Div(
        children = [
            dcc.Loading(
            html.Span(id = "show-news"),
                     )
            ])

Callback to plot graph


@app.callback(
    Output("stock-chart","figure"),
    Input("input-stock","value"),
)

def update_Graph(code):

    if code is None: raise dash.exceptions.PreventUpdate

    df1 = util.getStock("IBM") ## function which fetches the stock code and does slight pre-processing

    logger.warning("Model has been trained, begin sketch") 
    ### Assuming code fails here as the console does not log after this
    fig = px.line(df1, x = df1.index , y ="c")

    logger.warning("plot completed")
    
    return fig

Error message

image

What I have tried

In my attempts to trouble shoot this I tried:

  • Using a static excel spread sheet rather than api request ( made no difference )
  • Removing the “index” from the px.line function

I’ve seen this thread here Callback failed: the server did not respond

However callback timing wasn’t an issue as the callback takes seconds to process, and I’m not too familiar with Javascript to diagnose the problem in the console :frowning: .

Any help is greatly appreciated!

Thank you!