2

I'm trying to run (locally) a sample dash app code but I'm always getting a mistake while opening the window.

I'm using Jupyter Notebook and sometimes PyCharm for testing. The code I'm running is this:

import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
import plotly
import plotly.graph_objs as go                # for making plot.ly graph objects
from dash.dependencies import Input, Output
from collections import deque
import random

X = deque(maxlen = 20)
X.append(1)
Y = deque(maxlen = 20)
Y.append(1)

app = dash.Dash(__name__) 

# Layout
app.layout = html.Div([
    dcc.Graph(id = 'live-graph', animate = True),
    dcc.Interval(id = 'graph-update', interval = 1000)
])

# Callbacks
@app.callback(Output('live-graph', 'figure'),
              [Input('graph-update', 'n_intervals')])

def update_graph(input_data):             
    
    X.append(X[X[-1] + 1])                                  
    Y.append(Y[Y[-1] + (Y[-1]*random.uniform[-0.1, 0.1])])  
               
    data = gp.Scatter(
        x = list(X),               
        y = list(Y),               
        name = 'Temperature',      
        mode = 'lines + markers'   
    )
               
    return {'data':[data], 'layout':go.Layout(xaxis = dict(range = [min(X), max(X)]),
                                              yaxis = dict(range = [min(Y), max(Y)])
                                              )}

if __name__ == "__main__":
    app.run_server(host = '0.0.0.0', port = 8050, debug = True)

I already tried changing the port to 8050 and debug = False. Image Error

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Gerardo
  • 21
  • 5

1 Answers1

3

If you're using 0.0.0.0:8050 you should be accessing your site at localhost:8050.

coralvanda
  • 6,431
  • 2
  • 15
  • 25
  • I'm also getting that error using a Jupyter notebook. I tried changing my code to this: `app.run_server(host="localhost", debug=True, use_reloader=False)`, but still getting "this site can't be reached" error. Is my code correct? The URL looks like this when I try it: `http://localhost:8050/`. – Azurespot Mar 10 '22 at 22:23
  • 1
    [This](https://stackoverflow.com/questions/45490002/how-to-use-dash-within-jupyter-notebook-or-jupyterlab) might help with that. – coralvanda Mar 11 '22 at 00:21
  • 1
    Thanks! I added some Jupyter imports, but the main issue was my browser had its shields up. I disabled them and it rendered. – Azurespot Mar 11 '22 at 00:26
  • @Azurespot what does "browser had it's shields up" mean? – evan54 May 06 '22 at 10:34
  • @evan54 oh I use ad blockers a lot, and on Brave they make it easy to have their protections on or off. But sometimes having it on can cause issues, so you can turn them off as needed. They call it a "shields up or down" kind of thing. – Azurespot May 07 '22 at 23:53