Skip to content

Commit

Permalink
close #1084 - callback chain with sliders and multiple outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcjohnson committed Mar 6, 2020
1 parent 5b25247 commit 5694843
Showing 1 changed file with 66 additions and 4 deletions.
70 changes: 66 additions & 4 deletions tests/integration/callbacks/test_multiple_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time
from multiprocessing import Value

import pytest

import dash_html_components as html
import dash_core_components as dcc
import dash_table
Expand Down Expand Up @@ -45,10 +47,10 @@ def test_cbmt002_canceled_intermediate_callback(dash_duo):
# see https://github.com/plotly/dash/issues/1053
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(id='a', value="x"),
html.Div('b', id='b'),
html.Div('c', id='c'),
html.Div(id='out')
dcc.Input(id="a", value="x"),
html.Div("b", id="b"),
html.Div("c", id="c"),
html.Div(id="out")
])

@app.callback(
Expand Down Expand Up @@ -124,3 +126,63 @@ def b2(a2, selected_cells):
dash_duo.wait_for_text_to_equal("#a2", "a2: 2")
dash_duo.wait_for_text_to_equal("#b1", "b1: 'a1: 2'")
dash_duo.wait_for_text_to_equal("#b2", "b2: 'a2: 2', None")


@pytest.mark.parametrize("MULTI", [False, True])
def test_cbmt004_chain_with_sliders(MULTI, dash_duo):
app = dash.Dash(__name__)
app.layout = html.Div([
html.Button("Button", id="button"),
html.Div([
html.Label(id="label1"),
dcc.Slider(id="slider1", min=0, max=10, value=0),

]),
html.Div([
html.Label(id="label2"),
dcc.Slider(id="slider2", min=0, max=10, value=0),
])
])

if MULTI:
@app.callback(
[Output("slider1", "value"), Output("slider2", "value")],
[Input("button", "n_clicks")]
)
def update_slider_vals(n):
if not n:
raise PreventUpdate
return n, n
else:
@app.callback(Output("slider1", "value"), [Input("button", "n_clicks")])
def update_slider1_val(n):
if not n:
raise PreventUpdate
return n

@app.callback(Output("slider2", "value"), [Input("button", "n_clicks")])
def update_slider2_val(n):
if not n:
raise PreventUpdate
return n

@app.callback(Output("label1", "children"), [Input("slider1", "value")])
def update_slider1_label(val):
return "Slider1 value {}".format(val)

@app.callback(Output("label2", "children"), [Input("slider2", "value")])
def update_slider2_label(val):
return "Slider2 value {}".format(val)

dash_duo.start_server(app)

dash_duo.wait_for_text_to_equal("#label1", "")
dash_duo.wait_for_text_to_equal("#label2", "")

dash_duo.find_element("#button").click()
dash_duo.wait_for_text_to_equal("#label1", "Slider1 value 1")
dash_duo.wait_for_text_to_equal("#label2", "Slider2 value 1")

dash_duo.find_element("#button").click()
dash_duo.wait_for_text_to_equal("#label1", "Slider1 value 2")
dash_duo.wait_for_text_to_equal("#label2", "Slider2 value 2")

0 comments on commit 5694843

Please sign in to comment.