Dash TypeError when running dropdown example code

Hello,

Learning Dash. When I copy and run dropdown example code from Plotly website it produces error:
line 9, in
dcc.Dropdown([‘NYC’, ‘MTL’, ‘SF’], ‘NYC’, id=‘demo-dropdown’),
File “/Users/r/opt/anaconda3/lib/python3.9/site-packages/dash/development/base_component.py”, line 366, in wrapper
return func(*args, **kwargs)
TypeError: init() got multiple values for argument ‘id’

Code:

from dash import Dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output


app = Dash(__name__)
app.layout = html.Div([
    dcc.Dropdown(['NYC', 'MTL', 'SF'], 'NYC', id='demo-dropdown'),
    html.Div(id='dd-output-container')
])


@app.callback(
    Output('dd-output-container', 'children'),
    Input('demo-dropdown', 'value')
)
def update_output(value):
    return f'You have selected {value}'


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

Hi @rp1 and welcome to Dash :slight_smile:

The examples in the dash docs uses syntax that was new as of dash version 2.1.0 . If you upgrade to the latest version, then the error will go away. You will also be able to use the more concise import statements:

instead of:

from dash import Dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output

you can do this :cake: :

from dash import Dash, dcc, html, Input, Output
1 Like

Thanks, I got it working :slight_smile:

1 Like