Skip to content

Commit 913cb52

Browse files
authored
Merge pull request #2700 from plotly/fix/dynamic-callback-inputmap
Fix dynamic callbacks reset graphs.
2 parents 3adb9a9 + f044276 commit 913cb52

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

dash/dash-renderer/src/APIController.react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function storeEffect(props, events, setErrorLoading) {
166166
);
167167
} else if (
168168
dependenciesRequest.status === STATUS.OK &&
169-
isEmpty(graphs)
169+
(isEmpty(graphs) || graphs.reset)
170170
) {
171171
dispatch(
172172
setGraphs(

dash/dash-renderer/src/actions/requestDependencies.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {setGraphs} from './index';
33
import apiThunk from './api';
44

55
export function requestDependencies() {
6-
return (dispatch: any) => {
6+
return (dispatch: any, getState: any) => {
77
batch(() => {
8-
dispatch(setGraphs({}));
8+
const {graphs} = getState();
9+
dispatch(setGraphs({...graphs, reset: true}));
910
dispatch(
1011
apiThunk('_dash-dependencies', 'GET', 'dependenciesRequest')
1112
);

tests/integration/callbacks/test_dynamic_callback.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,34 @@ def on_click2(n_clicks2):
4242

4343
dash_duo.wait_for_element("#dynamic").click()
4444
dash_duo.wait_for_text_to_equal("#output-2", "Dynamic clicks 2")
45+
46+
47+
def test_dync002_dynamic_callback_without_element(dash_duo):
48+
app = Dash()
49+
50+
app.layout = html.Div(
51+
[
52+
html.Button("Add callbacks", id="add-callbacks"),
53+
html.Div(id="output"),
54+
]
55+
)
56+
57+
@app.callback(
58+
Output("output", "children"),
59+
Input("add-callbacks", "n_clicks"),
60+
_allow_dynamic_callbacks=True,
61+
prevent_initial_call=True,
62+
)
63+
def on_add_callback(_):
64+
@app.callback(Output("no-exist", "children"), Input("invalid", "n_clicks"))
65+
def addition(_):
66+
return "additional"
67+
68+
return html.Div("add callbacks")
69+
70+
dash_duo.start_server(app)
71+
72+
dash_duo.wait_for_element("#add-callbacks").click()
73+
dash_duo.wait_for_text_to_equal("#output", "add callbacks")
74+
75+
assert dash_duo.get_logs() == []

0 commit comments

Comments
 (0)