MCPcopy Index your code
hub / github.com/plotly/dash / test_cbwc003_same_keys

Function test_cbwc003_same_keys

tests/integration/callbacks/test_wildcards.py:244–299  ·  view source on GitHub ↗
(dash_duo)

Source from the content-addressed store, hash-verified

242
243
244def test_cbwc003_same_keys(dash_duo):
245 app = Dash(__name__, suppress_callback_exceptions=True)
246
247 app.layout = html.Div(
248 [
249 html.Button("Add Filter", id="add-filter", n_clicks=0),
250 html.Div(id="container", children=[]),
251 ]
252 )
253
254 @app.callback(
255 Output("container", "children"),
256 [Input("add-filter", "n_clicks")],
257 [State("container", "children")],
258 )
259 def display_dropdowns(n_clicks, children):
260 new_element = html.Div(
261 [
262 dcc.Dropdown(
263 id={"type": "dropdown", "index": n_clicks},
264 options=[
265 {"label": i, "value": i} for i in ["NYC", "MTL", "LA", "TOKYO"]
266 ],
267 ),
268 html.Div(id={"type": "output", "index": n_clicks}),
269 ]
270 )
271 return children + [new_element]
272
273 @app.callback(
274 Output({"type": "output", "index": MATCH}, "children"),
275 [Input({"type": "dropdown", "index": MATCH}, "value")],
276 [State({"type": "dropdown", "index": MATCH}, "id")],
277 )
278 def display_output(value, id):
279 return html.Div("Dropdown {} = {}".format(id["index"], value))
280
281 dash_duo.start_server(app)
282 dash_duo.wait_for_text_to_equal("#add-filter", "Add Filter")
283 dash_duo.select_dcc_dropdown(
284 '#\\{\\"index\\"\\:0\\,\\"type\\"\\:\\"dropdown\\"\\}', "LA"
285 )
286 dash_duo.wait_for_text_to_equal(
287 '#\\{\\"index\\"\\:0\\,\\"type\\"\\:\\"output\\"\\}', "Dropdown 0 = LA"
288 )
289 dash_duo.find_element("#add-filter").click()
290 dash_duo.select_dcc_dropdown(
291 '#\\{\\"index\\"\\:1\\,\\"type\\"\\:\\"dropdown\\"\\}', "MTL"
292 )
293 dash_duo.wait_for_text_to_equal(
294 '#\\{\\"index\\"\\:1\\,\\"type\\"\\:\\"output\\"\\}', "Dropdown 1 = MTL"
295 )
296 dash_duo.wait_for_text_to_equal(
297 '#\\{\\"index\\"\\:0\\,\\"type\\"\\:\\"output\\"\\}', "Dropdown 0 = LA"
298 )
299 dash_duo.wait_for_no_elements(dash_duo.devtools_error_count_locator)
300
301

Callers

nothing calls this directly

Calls 7

DashClass · 0.90
select_dcc_dropdownMethod · 0.80
find_elementMethod · 0.80
wait_for_no_elementsMethod · 0.80
start_serverMethod · 0.45
clickMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…