Skip to content
Advertisement

Plotly Dash ZMQError: Address already in use

I am testing Plotly Dash as a possible dashboarding tool.

I am trying to run one of the charts found in the documentation: https://plotly.com/python/bar-charts/

import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
import plotly.express as px

df = px.data.tips()
days = df.day.unique()

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Dropdown(
        id="dropdown",
        options=[{"label": x, "value": x} for x in days],
        value=days[0],
        clearable=False,
    ),
    dcc.Graph(id="bar-chart"),
])

@app.callback(
    Output("bar-chart", "figure"), 
    [Input("dropdown", "value")])
def update_bar_chart(day):
    mask = df["day"] == day
    fig = px.bar(df[mask], x="sex", y="total_bill", 
                 color="smoker", barmode="group")
    return fig

app.run_server(debug=True, port=8049)

When I run this I get an error. Here is the end of the trace callback:

File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Address already in use

As you can see from my example, I have already tried altering the port to avoid this error. I have tried many ports around 8050, but they all seem to be “already in use.” My guess is that Dash reserves the port then tries to use it but sees that it’s already reserved, not knowing that it was reserved for the process it was about to execute.

Does anyone know how to fix this error?

Advertisement

Answer

If you are running it from jupyter-notebook or jupyter-lab, you should run the app server as:

app.run_server(debug=True, port=8049, use_reloader=False)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement