I’ve built a web app using Panel and PyScript. It uses the DatePicker widget
This operates as expected on desktop devices (tested using Pop_OS! and Chrome), but when opened on a Pixel5 using Android the native Date Time selector is used.
When the picker is used, the datepicker.start
and datepicker.end
properties don’t seem to be displayed, e.g. you can pick a date outside these values.
Additionally when the date is selected, it seems to return a str
value rather than the datetime
value documented:
2023-02-15 15:36:10,195 ERROR: panel.reactive - Callback failed for object named "" changing property {'value': ''}
Traceback (most recent call last):
File "/lib/python3.10/site-packages/panel/reactive.py", line 318, in _process_events
self.param.update(**self_events)
File "/lib/python3.10/site-packages/param/parameterized.py", line 1895, in update
setattr(self_or_cls, k, v)
File "/lib/python3.10/site-packages/param/parameterized.py", line 367, in _f
instance_param.__set__(obj, val)
File "/lib/python3.10/site-packages/param/parameterized.py", line 369, in _f
return f(self, obj, val)
File "/lib/python3.10/site-packages/param/__init__.py", line 625, in __set__
super(Dynamic,self).__set__(obj,val)
File "/lib/python3.10/site-packages/param/parameterized.py", line 369, in _f
return f(self, obj, val)
File "/lib/python3.10/site-packages/param/parameterized.py", line 1201, in __set__
self._validate(val)
File "/lib/python3.10/site-packages/param/__init__.py", line 909, in _validate
self._validate_value(val, self.allow_None)
File "/lib/python3.10/site-packages/param/__init__.py", line 1930, in _validate_value
raise ValueError(
ValueError: Date parameter 'value' only takes datetime and date types, not type <class 'str'>.
Which then when passed to the dependant function throws an error.
How should I be using this widget in this context?
An operational version is live here
The code generating this is effectively as simple as:
default_data_url = (
"https://raw.githubusercontent.com/DaveParr/engi-alpha-data/develop/GasHH2022.csv"
)
default_data = cf.read_file(open_url(default_data_url))
date_picker = pn.widgets.DatetimePicker()
date_picker.start = pd.to_datetime(default_data.index.min().to_timestamp())
date_picker.value = pd.to_datetime(default_data.index.max().to_timestamp())
date_picker.end = pd.to_datetime(default_data.index.max().to_timestamp())
I can make a more contained example if anyone would find that helpful