-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Hi, I noticed a small issue with dcc.Location. Callbacks having Input('url', 'search') are fired twice with every change of the parameter. Below is a small demo
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output, State
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(dcc.Input(id='input-box', type='text')),
html.Div(html.Button('Submit', id='button')),
html.Div('', id='div1'),
html.Div('', id='div2'),
])
@app.callback(
Output('url', 'search'),
[Input("button", "n_clicks")],
[State("input-box", "value")]
)
def update_url(n, value):
if not n:
raise dash.exceptions.PreventUpdate
print(f'update url, n_clicks={n} value={value}')
return f'?search={value}'
# This callback is called twice
@app.callback(
Output('div1', 'children'),
[Input('url', 'search')]
)
def update_div1(s):
print(f'update div1 {s}')
return s
@app.callback(
Output('div2', 'children'),
[Input('div1', 'children')]
)
def update_div2(s):
print(f'update div2 {s}')
return s
if __name__ == '__main__':
app.run_server(debug=True)
Each time the button is submitted, the output is like this, which shows that update_div1 function runs twice
update url, n_clicks=1 value=123
update div1 ?search=123
update div1 ?search=123
update div2 ?search=123
Environment
python 3.6
dash==1.1.1
dash-core-components==1.1.1
dash-daq==0.1.0
dash-html-components==1.0.0
dash-renderer==1.0.0
dash-table==4.1.0
Metadata
Metadata
Assignees
Labels
No labels