geds133
geds133

Reputation: 1485

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?

Upvotes: 13

Views: 28443

Answers (7)

Mostafa90
Mostafa90

Reputation: 1706

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)

Upvotes: 0

Nesha25
Nesha25

Reputation: 408

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

Upvotes: 2

GEDS27
GEDS27

Reputation: 25

I did this change:

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

And the code worked fine for me!

Upvotes: 1

Patrick Cree
Patrick Cree

Reputation: 39

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.

Upvotes: 0

Brendan
Brendan

Reputation: 2075

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.

Upvotes: 2

kha
kha

Reputation: 266

First check if you are accessing the right port, the default one (usually) is 8050: http://localhost:8050/

Also, check if there is another Dash code running, it might be occupying the port.

If it does not work, try determining the host as an argument in app.runserver(args), like this:

app.run_server(host='0.0.0.0', debug=True)

You might also want to determine the port as an argument like this:

app.run_server(host='0.0.0.0', port=8050, debug=True)

Upvotes: 11

Aqeel Haider
Aqeel Haider

Reputation: 79

Change

app.run_server(debug=True)

to

app.run_server(debug=False)

and then try.

Upvotes: 6

Related Questions