-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
(Calendar + clock) widget #1975
Comments
I have been playing around with the existing Datepicker in panel, the bokeh model and flatpickr. flatpickr has a option to enable time, and I got a working code of it in action (maybe with some small hacks...) datetimepicker.mp4 |
this is awesome !!! I was using a JS library, but it would be nice if something like this is incorporated to panel you can check the JS library here https://discourse.holoviz.org/t/elegant-date-and-time-picker/1262/3?u=nghenzi2019 |
Awesome both you @hoxbro and the work |
Both of those look fabulously useful! |
Can you submit a PR? Would love to do this. |
To be clear, in the long run we should upstream the widgets to bokeh but I'd love to get these into Panel asap. |
We have the nice Panel DatetimePicker now, but unfortunately I just found out it doesn't like the datetime64 objects from xarray (and pandas, I guess). Here's a short reproducible notebook showing the problem (screenshot below): |
@philippjfr please let me know if I should raise a new issue -- I would be happy to do so. |
The main problem is that your data is discrete and that DatetimePicker can accept any datetime value. A way to get this to work is to find the last value in the dataset and plot that. Here is an example of how it could be done. import hvplot.xarray # noqa
import pandas as pd
import panel as pn
import xarray as xr
xr_ds = xr.tutorial.open_dataset("air_temperature")
dt = pd.to_datetime(xr_ds.time)
datetime_widget = pn.widgets.DatetimePicker(
value=dt.min(), start=dt.min(), end=dt.max()
)
def plot(t):
t = dt[dt.get_indexer([t], method="ffill")[0]] # Find the last valid value
return xr_ds["air"].sel(time=t).hvplot(x="lon", y="lat")
pn.Column(pn.bind(plot, datetime_widget), datetime_widget) screenrecord-2022-09-14_11.33.33.mp4 |
I guess there could be a variation of a DatetimePicker that only allows to pick in a discrete list of date time values, everything else being greyed out. That'd be a feature request on Panel. Edit: That would work best for the DatePicker, as greying out the clock is trickier. |
I think you just described |
It is actually easier. def plot(t):
return xr_ds["air"].sel(time=t, method="ffill").hvplot(x="lon", y="lat") The Edit: |
Wow, this is getting easier and easier! The only thing that didn't work quite as expected was that I was hoping that |
The |
It's not currently easy for a user to select a datetime value in Panel. Current options:
I think it would be valuable to have a datetime widget that is a drop-in replacement for the Datetimeinput widget, returning a single datetime64 value, but with user-friendly controls for people thinking of a specific time on a specific date: a calendar to select the date, and hh:mm:ss text boxes to select the time. Obviously we can build such functionality already out of Bokeh widgets, but then you get date, hour, minute, and seconds values separately rather than a single datetime value useful for feeding to something like Pandas. Needing to select a datetime seems like a common and typical use case, and so I think there ought to be a straightforward drop-in widget like this to handle it.
The text was updated successfully, but these errors were encountered: