'dash app refusing to start: '127.0.0.1 refused to connect.'

I am trying to run the example dash application but upon trying to run, the browser says it is refusing to connect. I have checked and Google Chrome has access through the firewall.

The example code is:

import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
html.H1(children='Hello Dash'),

html.Div(children='''
    Dash: A web application framework for Python.
'''),

dcc.Graph(
    id='example-graph',
    figure={
        'data': [
            {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
            {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
        ],
        'layout': {
            'title': 'Dash Data Visualization'
        }
    }
)
])

if __name__ == '__main__':
    app.run_server(debug=True)

Here is a picture of my browser:

enter image description here

Does anyone understand this?



Solution 1:[1]

Change

app.run_server(debug=True)

to

app.run_server(debug=False)

and then try.

Solution 2:[2]

I had the same problem, and discovered I forgot to launch the app by running python app.py before visiting my browser. (Assuming your file is named app.py). Once I did this, all was well.

https://dash.plotly.com/layout shows how to do this

Solution 3:[3]

I ran into a similar issue. I was running Jupyter Lab in a container on a remote server. I can't offer specific code because I don't know your configuration, but for me this involved forwarding from 127.0.0.1:8050 to port 8050 on the container.

Hopefully this can help someone in the future.

Solution 4:[4]

Was experiencing the same issue and setting "debug=False" definitely was not a solution as "debug=True" is a part of the tutorial to show the "hot-reloading" functionality (see https://dash.plotly.com/layout).

Looked a bit and from the site below I noticed "alitarraf" mentioning that python could get stuck on an old version: https://github.com/plotly/dash/issues/108

After seeing that I killed "python.exe" in the details tab of task manager. This resolved the issue for me.

Edit: After a reboot it seems like the issue also is gone.

Solution 5:[5]

I did this change:

if __name__ == '__main__':
    app.run_server(host='localhost',port=8005)

And the code worked fine for me!

Solution 6:[6]

I had the same problem, I was launching the app in the console (in Rstudio IDE), try to use the terminal, with the good python interpreter python3 app.py

And changing the port could help if the default one is already taken.

if __name__ == '__main__':
    app.run_server(host='0.0.0.0', port=8007, debug=False)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aqeel Haider
Solution 2
Solution 3 Brendan
Solution 4
Solution 5 GEDS27
Solution 6