-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add outputs_list to window.dash_clientside.callback_context #2881
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
177bc08
Add outputs and outputs_list to window.dash_clientside.callback_context
insistence 95d4bdb
Update CHANGELOG entry
insistence 58bbe0b
Merge branch 'dev' into insistence-dev
insistence ee3ad68
Update dash/dash-renderer/src/actions/callbacks.ts
insistence bc4893c
rerun tests
insistence 31e4a10
Update changelog
insistence f7fed34
Update changelog
insistence File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
tests/integration/clientside/test_clientside_outputs_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
from dash import ( | ||
Dash, | ||
Input, | ||
Output, | ||
html, | ||
clientside_callback, | ||
) | ||
|
||
|
||
def test_clol001_clientside_outputs_list_by_single_output(dash_duo): | ||
app = Dash(__name__) | ||
app.layout = html.Div( | ||
[html.Button("trigger", id="trigger-demo"), html.Pre(id="output-demo")], | ||
style={"padding": 50}, | ||
) | ||
|
||
clientside_callback( | ||
"""(n_clicks) => { | ||
return JSON.stringify(window.dash_clientside.callback_context.outputs_list); | ||
}""", | ||
Output("output-demo", "children"), | ||
Input("trigger-demo", "n_clicks"), | ||
prevent_initial_call=True, | ||
) | ||
|
||
dash_duo.start_server(app) | ||
|
||
trigger_clicker = dash_duo.wait_for_element("#trigger-demo") | ||
trigger_clicker.click() | ||
dash_duo.wait_for_text_to_equal( | ||
"#output-demo", | ||
'{"id":"output-demo","property":"children"}', | ||
) | ||
|
||
|
||
def test_clol002_clientside_outputs_list_by_multiple_output1(dash_duo): | ||
app = Dash(__name__) | ||
app.layout = html.Div( | ||
[ | ||
html.Button("trigger", id="trigger-demo"), | ||
html.Pre(id="output-demo1"), | ||
html.Pre(id="output-demo2"), | ||
], | ||
style={"padding": 50}, | ||
) | ||
|
||
clientside_callback( | ||
"""(n_clicks) => { | ||
return [JSON.stringify(window.dash_clientside.callback_context.outputs_list), JSON.stringify(window.dash_clientside.callback_context.outputs_list)]; | ||
}""", | ||
[Output("output-demo1", "children"), Output("output-demo2", "children")], | ||
Input("trigger-demo", "n_clicks"), | ||
prevent_initial_call=True, | ||
) | ||
|
||
dash_duo.start_server(app) | ||
|
||
dash_duo.find_element("#trigger-demo").click() | ||
dash_duo.wait_for_text_to_equal( | ||
"#output-demo1", | ||
'[{"id":"output-demo1","property":"children"},{"id":"output-demo2","property":"children"}]', | ||
) | ||
dash_duo.wait_for_text_to_equal( | ||
"#output-demo2", | ||
'[{"id":"output-demo1","property":"children"},{"id":"output-demo2","property":"children"}]', | ||
) | ||
|
||
|
||
def test_clol003_clientside_outputs_list_by_multiple_output2(dash_duo): | ||
app = Dash(__name__) | ||
app.layout = html.Div( | ||
[ | ||
html.Button("trigger1", id="trigger-demo1"), | ||
html.Button("trigger2", id="trigger-demo2"), | ||
html.Pre(id="output-demo1"), | ||
html.Pre(id="output-demo2"), | ||
], | ||
style={"padding": 50}, | ||
) | ||
|
||
clientside_callback( | ||
"""(n_clicks1, n_clicks2) => { | ||
if (window.dash_clientside.callback_context.triggered_id === 'trigger-demo1') { | ||
return [JSON.stringify(window.dash_clientside.callback_context.outputs_list), window.dash_clientside.no_update]; | ||
} else if (window.dash_clientside.callback_context.triggered_id === 'trigger-demo2') { | ||
return [window.dash_clientside.no_update, JSON.stringify(window.dash_clientside.callback_context.outputs_list)]; | ||
} | ||
return [window.dash_clientside.no_update, window.dash_clientside.no_update]; | ||
}""", | ||
[Output("output-demo1", "children"), Output("output-demo2", "children")], | ||
[Input("trigger-demo1", "n_clicks"), Input("trigger-demo2", "n_clicks")], | ||
prevent_initial_call=True, | ||
) | ||
|
||
dash_duo.start_server(app) | ||
|
||
dash_duo.find_element("#trigger-demo1").click() | ||
dash_duo.wait_for_text_to_equal( | ||
"#output-demo1", | ||
'[{"id":"output-demo1","property":"children"},{"id":"output-demo2","property":"children"}]', | ||
) | ||
dash_duo.find_element("#trigger-demo2").click() | ||
dash_duo.wait_for_text_to_equal( | ||
"#output-demo2", | ||
'[{"id":"output-demo1","property":"children"},{"id":"output-demo2","property":"children"}]', | ||
) | ||
|
||
|
||
def test_clol004_clientside_outputs_list_by_no_output(dash_duo): | ||
app = Dash(__name__) | ||
app.layout = html.Div( | ||
[html.Button("trigger", id="trigger-demo"), html.Pre(id="output-demo")], | ||
style={"padding": 50}, | ||
) | ||
|
||
clientside_callback( | ||
"""(n_clicks) => { | ||
window.dash_clientside.set_props('output-demo', {'children': JSON.stringify(window.dash_clientside.callback_context.outputs_list)}); | ||
}""", | ||
Input("trigger-demo", "n_clicks"), | ||
prevent_initial_call=True, | ||
) | ||
|
||
dash_duo.start_server(app) | ||
|
||
dash_duo.find_element("#trigger-demo").click() | ||
dash_duo.wait_for_text_to_equal( | ||
"#output-demo", | ||
"", | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to go in a new section above the
## [2.17.1]
with a## [UNRELEASED]
title.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your correction. I have made the necessary changes as per your suggestion.