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

pn.widgets() helper function #1826

Closed
jbednar opened this issue Dec 4, 2020 · 0 comments · Fixed by #3589
Closed

pn.widgets() helper function #1826

jbednar opened this issue Dec 4, 2020 · 0 comments · Fixed by #3589
Labels
type: feature A major new feature

Comments

@jbednar
Copy link
Member

jbednar commented Dec 4, 2020

The pn.panel(obj) function is really useful for creating an appropriate Pane type from a given obj without having to think very deeply about the space of possible Panes, as long as what's returned is close enough to what we want.

Can we have something like that for widgets, i.e. pn.widget(obj), constructing an appropriate widget type for an object in the same way pn.interact does for function arguments, but in a standalone way that can be used in an example like the following? Here I'm assuming a user is starting with some code that works for specific lon, lat values, and wants to add widgets for those:

import panel as pn, xarray as xr, holoviews as hv, hvplot.xarray
pn.extension()

ds = xr.tutorial.open_dataset('air_temperature')
ds.interactive.sel(lon=200, lat=40, method="nearest").hvplot('time')

Right now they need to know the right magic to instantiate a widget first:

lon = pn.widgets.IntSlider(name="lon", start=200, end=360)
lat = pn.widgets.IntSlider(name="lat", start=15,  end=80)
ds.interactive.sel(lon=lon, lat=lat, method="nearest").hvplot('time')

But it would be great if they could just use the widget abbreviations described at https://panel.holoviz.org/user_guide/Interact.html to construct a suitable widget:

ds.interactive.sel(lon=pn.widget(200), lat=pn.widget(15, 80, 1, 40), method="nearest").hvplot('time')

I'm not sure how this mechanism would intersect with the magic that hvPlot already does with pn.widgets.DiscreteSlider to figure out the discrete set of objects; clearly being able to auto-discover that sort of information is really helpful, but I don't know the limits on how to do that practically. In any case just getting any sort of widget is a great start, because then people have a working app and can go from there...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A major new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants