-
-
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
Inline clientside callbacks #967
Conversation
@jjaraalm you're on a roll 🏎 I very much like your implementation with I'd like to see if we can get rid of the I'm not a fan of writing JS code directly in a Python function body, and I don't see how it can be a stepping stone without later becoming a breaking change. If it's alright with you, let's leave this flavor out unless and until we're ready to do the transpiled version. |
Thanks for the feedback. I wasn't thinking so much about the implications of putting it in I agree with your assessment of the utility of namespace/function name for inline scripts. Really I only see that being used for intricate, overly complex, and probably not well-documented callback ... which I'm guilty of sometimes haha. I think JS in python feels dirty, but that said I dislike code-in-strings even more. It's more clear that it's a foreign language, but also there's no easy way to get syntax highlighting or linting in editors (that I know of). I've always found code-in-strings to be a pain to write and debug. I understand your points though, and we can leave it out. |
…into inline_clientside
I decided to create a new namespace prefixed by |
`dash.dependencies.ClientsideFunction(namespace, function_name)` | ||
argument that describes which JavaScript function to call | ||
(Dash will look for the JavaScript function at | ||
`window[namespace][function_name]`). | ||
`window.dash_clientside[namespace][function_name]`), or it may take |
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.
good catch! 🔬
Alright, Looks good to me! Just needs a changelog (and updating so it doesn't conflict with your other PR 😏) and we'll be ready to go. |
@alexcjohnson @jjaraalm Looking into the DashR parity implementation and came to the conclusion that we wanted to prepend the namespace with |
Sorry guys, was traveling. This should take care of it I think. |
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.
Love it, thanks for the finishing touches. 💃
I'm going to hold off merging for a little bit though in case we want to make a patch release on Monday's 1.6.0
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.
💃 @jjaraalm Took the liberty of merging in dev changes. Will merge it in once the build passes one last time. Again thanks for the contribution! The next planned release is 1.7.0
around 11/25.
I've updated to dash=1.7 and want to use the new inline callbacks feature, but got the following error: TypeError: clientside_callback() got an unexpected keyword argument 'source' and when i want to use the native_js_callback syntax, it gave the error: callback() got an unexpected keyword argument 'clientside' |
@ieipi the final implementation is not as described in the lead comment for the PR. See https://community.plot.ly/t/dash-v1-7-0-released/31961 for an example. |
…ted-git-info-2.8.9 Bump hosted-git-info from 2.7.1 to 2.8.9
…t-info-2.8.9 Bump hosted-git-info from 2.7.1 to 2.8.9
Addresses at least part of #956 and adds support for writing JS clientside callbacks in python source.
Adds explicit JS source injection through a new keyword argument to
Dash.clientside_callback
:Also adds source injection via the
Dash.callback
decorator. This probably should be explained or documented better so that users don't think they can write arbitrary python code here. Eventually I would like to add support for transpiling python -> JS, but this is just a stepping stone.Contributor Checklist
Dash.clientside_callback
Dash.callback
optionals
CHANGELOG.md