Error loading dependencies in using Button Callback

Hi,
I am trying to run one of Dash basic examples. This is the code:

import dash
import dash_html_components as html
import dash_core_components as dcc

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
    html.Div(dcc.Input(id='input-box', type='text')),
    html.Button('Submit', id='button'),
    html.Div(id='output-container-button',
             children='Enter a value and press submit')
])


@app.callback(
    dash.dependencies.Output('output-container-button', 'children'),
    [dash.dependencies.Input('button', 'n_clicks')],
    [dash.dependencies.State('input-box', 'value')])
def update_output(n_clicks, value):
    return 'The input value was "{}" and the button has been clicked {} times'.format(
        value,
        n_clicks
    )


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

but when I want to connect to dash, I get the “Error loading dependencies” error.

I installed dash components with commands from here: https://dash.plot.ly/installation

You might have an out of date Dash dependency. They are now all locked to the correct versions, so do pip install -U dash and try again.

1 Like

Hi! I have the similar issue, even after pip install -U dash.
I continue getting:

syntax error external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]

even when using the same code as the sample reference page. Here’s the code (and link) I copied/pasted to test if it works in jupyter. Am I missing something?

Thanks in advance!

page link: must add https dash.plot.ly/dash-core-components/dropdown

import dash
import dash_html_components as html
import dash_core_components as dcc

external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]

app = dash.Dash(name, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Dropdown(
id=‘my-dropdown’,
options=[
{‘label’: ‘New York City’, ‘value’: ‘NYC’},
{‘label’: ‘Montreal’, ‘value’: ‘MTL’},
{‘label’: ‘San Francisco’, ‘value’: ‘SF’}
],
value=‘NYC’
),
html.Div(id=‘output-container’)
])

@app.callback(
dash.dependencies.Output(‘output-container’, ‘children’),
[dash.dependencies.Input(‘my-dropdown’, ‘value’)])
def update_output(value):
return ‘You have selected “{}”’.format(value)

if name == ‘main’:
app.run_server(debug=True)

Dash doesn’t work with Jupyter out of the box. There’s a few projects that can help make that work. Plotly has one for Jupyter lab (https://github.com/plotly/jupyterlab-dash) and there’s also this one: https://github.com/GibbsConsulting/jupyter-plotly-dash

Perhaps try just running with Python directly and then see if you have the issue first.

Thanks! i’ll give it a go