Skip to content
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

Added jscallback method to Viewable objects #665

Merged
merged 11 commits into from Oct 28, 2019
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Sep 25, 2019

While jslink is very convenient for linking two objects it is also limited because it only exposes the source and target object, doesn't allow providing just a callback on the source and is not really designed around providing custom code.

This PR introduces a .jscallback method which can be used to add arbitrary JS callbacks, e.g. this example takes the values of the two slider and triggers an alert:

a = pn.widgets.Button(name='Add')
slider1 = pn.widgets.IntSlider()
slider2 = pn.widgets.IntSlider()

a.jscallback(clicks='alert(slider1.value+slider2.value)', args={'slider1': slider1, 'slider2': slider2})

pn.Row(a, slider1, slider2)

Cc: @xavArtley I know you were playing around with adding args to links but I think this generalizes this more.

  • Clean up links.py
  • Improve docstrings
  • Write tests
  • Write docs

@philippjfr philippjfr added the type: enhancement label Sep 25, 2019
@philippjfr philippjfr force-pushed the philippjfr/jscallbacks branch 3 times, most recently from 82b073a to ce2ebf5 Compare Sep 25, 2019
@xavArtley xavArtley mentioned this pull request Oct 20, 2019
@philippjfr philippjfr merged commit d451a4b into master Oct 28, 2019
1 of 2 checks passed
@philippjfr philippjfr deleted the philippjfr/jscallbacks branch Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant