Skip to content

Commit

Permalink
Merge pull request #2700 from plotly/fix/dynamic-callback-inputmap
Browse files Browse the repository at this point in the history
Fix dynamic callbacks reset graphs.
  • Loading branch information
alexcjohnson authored Nov 27, 2023
2 parents 3adb9a9 + f044276 commit 913cb52
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dash/dash-renderer/src/APIController.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function storeEffect(props, events, setErrorLoading) {
);
} else if (
dependenciesRequest.status === STATUS.OK &&
isEmpty(graphs)
(isEmpty(graphs) || graphs.reset)
) {
dispatch(
setGraphs(
Expand Down
5 changes: 3 additions & 2 deletions dash/dash-renderer/src/actions/requestDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {setGraphs} from './index';
import apiThunk from './api';

export function requestDependencies() {
return (dispatch: any) => {
return (dispatch: any, getState: any) => {
batch(() => {
dispatch(setGraphs({}));
const {graphs} = getState();
dispatch(setGraphs({...graphs, reset: true}));
dispatch(
apiThunk('_dash-dependencies', 'GET', 'dependenciesRequest')
);
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/callbacks/test_dynamic_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,34 @@ def on_click2(n_clicks2):

dash_duo.wait_for_element("#dynamic").click()
dash_duo.wait_for_text_to_equal("#output-2", "Dynamic clicks 2")


def test_dync002_dynamic_callback_without_element(dash_duo):
app = Dash()

app.layout = html.Div(
[
html.Button("Add callbacks", id="add-callbacks"),
html.Div(id="output"),
]
)

@app.callback(
Output("output", "children"),
Input("add-callbacks", "n_clicks"),
_allow_dynamic_callbacks=True,
prevent_initial_call=True,
)
def on_add_callback(_):
@app.callback(Output("no-exist", "children"), Input("invalid", "n_clicks"))
def addition(_):
return "additional"

return html.Div("add callbacks")

dash_duo.start_server(app)

dash_duo.wait_for_element("#add-callbacks").click()
dash_duo.wait_for_text_to_equal("#output", "add callbacks")

assert dash_duo.get_logs() == []

0 comments on commit 913cb52

Please sign in to comment.