Dash object has no attribute run

Hi, I am new to Dash and was wondering if anyone who managed to complete the tutorial could give me some pointers?

I’m currently working on this tutorial https://dash.plotly.com/tutorial and noticed some issues with mine.

  1. I have to change my code from “app.run” to “app.run_server” since it would throw error “Dash object has no attribute run”.
  2. The table wouldn’t load at all for this line of code: dash_table.DataTable(data=df.to_dict('records'), page_size=6). This was somewhat odd since the graph was able to load the csv data without issues.
  3. When I try out the radio button tutorial, I encountered these error messages per screenshot:

If it helps, this is my code:

# Import packages
from dash import Dash, html, dash_table, dcc, callback, Output, Input
import pandas as pd
import plotly.express as px

# Incorporate data
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv')

# Dash constructor, responsible for  initializing app
app = Dash(__name__)

app.layout = html.Div([
    html.Div(children='My First App with Data, Graph, and Controls'),
    html.Hr(),
    dcc.RadioItems(options=['pop', 'lifeExp', 'gdpPercap'], value='lifeExp', id='controls-and-radio-item'),
    dash_table.DataTable(data=df.to_dict('records'), page_size=6),
    dcc.Graph(figure={}, id='controls-and-graph')
])

# Add controls to build the interaction
@callback(
    Output(component_id='controls-and-graph', component_property='figure'),
    Input(component_id='controls-and-radio-item', component_property='value')
)
def update_graph(col_chosen):
    fig = px.histogram(df, x='continent', y=col_chosen, histfunc='avg')
    return fig

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

Hi @viviensiu and welcome to Dash :slightly_smiling_face:

It looks like you are running an old version of Dash. Try upgrading the to the most recent (currently 2.14.2). To double check the version in the app try adding:


import dash
print("dash version=", dash.__version__)

1 Like

Hi @AnnMarieW I installed Dash thru conda: conda install -c conda-forge dash. The version was 2.0.0

Somehow running conda update dash downgraded the version to 1.19.0

Could you please direct me on how to upgrade it to the latest version? Thank you.

hi @viviensiu
That’s a good question. I don’t have conda installed on my computer, but you should be able to type:

conda install -c conda-forge dash=2.14.2 

Or earlier versions. Use this link to see the latest version of Dash on Anaconda,.

2 Likes

Hi @adamschroeder , thanks for the tip. After a few updates on Dash, Python and Conda on my (rather outdated) conda environment it finally worked!
Funnily though, I do not see the http link in my Spyder 5.4.3 console, and there were similar issues reported like this here: https://stackoverflow.com/questions/76911502/http-link-on-plotly-dash-is-not-showing-in-spyder

I’d have to memorize the default localhost link as it is still able to load there.

can you share your code please?

Do you see the http link anywhere else inside Spyder?

Here is the code as requested:

from dash import Dash, html, dash_table, dcc, callback, Output, Input
import pandas as pd
import plotly.express as px

# Incorporate data
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv')

# Initialize the app - incorporate css
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div([
    html.Div(className='row', children='My First App with Data, Graph, and Controls',
             style={'textAlign': 'center', 'color': 'blue', 'fontSize': 30}),

    html.Div(className='row', children=[
        dcc.RadioItems(options=['pop', 'lifeExp', 'gdpPercap'],
                       value='lifeExp',
                       inline=True,
                       id='my-radio-buttons-final')
    ]),

    html.Div(className='row', children=[
        html.Div(className='six columns', children=[
            dash_table.DataTable(data=df.to_dict('records'), page_size=11, style_table={'overflowX': 'auto'})
        ]),
        html.Div(className='six columns', children=[
            dcc.Graph(figure={}, id='histo-chart-final')
        ])
    ])
])

# Add controls to build the interaction
@callback(
    Output(component_id='histo-chart-final', component_property='figure'),
    Input(component_id='my-radio-buttons-final', component_property='value')
)
def update_graph(col_chosen):
    fig = px.histogram(df, x='continent', y=col_chosen, histfunc='avg')
    return fig

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

After running the code in Spyder 5.4.3, I can only see the following in console:

I have read in a couple other stackoverflow posts that this happens in Spyder. Not sure what the Spyder solution is.

But one workaround, which I think you mentioned, is to save http://127.0.0.1:8050/ as a browser bookmark for easier access. Or, although it’s not ideal, you can try to switch to PyCharm or VS Code. I haven’t heard this happen with those platforms.

Thanks for taking a look @adamschroeder , will keep this in mind!