-
-
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
Issue-1213 clientside callback_context Initial Commit #1240
Issue-1213 clientside callback_context Initial Commit #1240
Conversation
@MrDawson this looks great! Just a few comments: Rather than checking for its existence, I'd just set up
Looks like our
Hmm, good to know! None of our core team works on Windows normally but this is of course an important environment to support. We do have a Windows test run on CI |
|
Yeah we really need a better error message from function stringifySorted(v) {
if (Array.isArray(v)) {
return '[' + v.map(stringifySorted).join(',') + ']';
}
if (v && typeof v === 'object') {
const parts = Object.keys(v)
.sort()
.map(k => JSON.stringify(k) + ':' + stringifySorted(v[k]));
return '{' + parts.join(',') + '}';
}
return JSON.stringify(v);
} If that doesn't work, in order to debug you can just put in a few seconds
Not useful for client-side callbacks. This is mostly to support server-side callbacks setting cookies.
Maybe not super important, but we do this server side so that if someone tries to use |
Love it! Thanks for the changes, and your tests are fantastic. Glad to see they work without a fancy custom stringify after all 🎉 The only last thing I'd ask for is a changelog entry. Just add |
🎉Thanks for your quick feedback! |
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.
Excellent, thanks again @MrDawson! 💃
Hi, beginner here having trouble getting this to work. I get "undefined" for 'window.dash_clientside.callback_context;' Thanks |
hi @BaconEggsRL |
I have similar issue as these folks: I can only get the function to work as an inline function. When I try to put it in .js file I get undefined error. Error:
Version
assets\dashAgGridComponentFunctions.js
test_clientside_callback.py
|
@Coding-with-Adam I think I fixed it just now. I don't think there is any issue with dash just some simple mistakes. Two issues:
It does not seem to matter the name of the .js file as long as it is in the assets folder. folder/test.py Thank you |
Clientside callback_context
Here’s a first pass at Issue-1213, adding callback_context to clientside callbacks. Before I get too much further into the weeds, I wanted to get a PR going to discuss.
The idea was to mimic the behavior of the serverside dash.callback_context as closely as possible. I think this is probably the way to go for consistency’s sake, but I am of course open to suggestions.
From within a clientside callback function, we can now use the trick with “triggered” to figure out which input triggered the callback:
triggered = dash_clientside.callback_context.triggered.map(t => t[“prop_id”]);
The first new test
test_clsd009_clientside_callback_context
is currently passing.Contributor Checklist
states
states_list
Add propertyresponse
(need to check if this even makes sense in the clientside context)Two quick off-topic things:
pip install -e .[testing,dev]
:requests 2.21.0 has requirement urllib3<1.25,>=1.21.1, but you'll have urllib3 1.25.9 which is incompatible.
I’m on Windows, Python 3.7