I have a chart plotting datetime data between a Start and End date the user selects from 2 Panel datepickers. At the moment the user can select an End date than comes before the Start date, or a Start date that falls after the selected End date. There is no warning to the user that the dates they've selected are invalid.I'm looking for a way to generate a warning, or restrict the dates available for selection on one datepicker depending on what was selected in the other.
I've worked with @pn.depends before in dropdown selectors (How do i automatically update a dropdown selection widget when another selection widget is changed? (Python panel pyviz)). I'm struggling to figure out how to achieve dependency between 2 date pickers... Any ideas?
Here is a list of attributes of the datepicker class. Those in bold sound promising?
'add_periodic_callback', 'align', 'app', 'aspect_ratio', 'background', 'clone', 'css_classes', 'debug', 'defaults', 'disabled', 'embed', 'end', 'force_new_dynamic_value', 'get_param_values', 'get_root', 'get_value_generator', 'height', 'height_policy', 'initialized', 'inspect_value', 'jslink', 'link', 'margin', 'max_height', 'max_width', 'message', 'min_height', 'min_width', 'name', 'param', 'params', 'pprint', 'print_param_defaults', 'print_param_values', 'save', 'script_repr', 'select', 'servable', 'server_doc', 'set_default', 'set_dynamic_time_fn', 'set_param', 'show', 'sizing_mode', 'start', 'state_pop', 'state_push', 'value', 'verbose', 'warning', 'width', 'width_policy'
import panel as pn
from panel.interact import interact
from bokeh.plotting import figure
[...]
date_picker = pn.widgets.DatePicker(name='Select date range Start', value=datetime(2020, 1, 1, tzinfo=timezone.utc))
date_picker_2 = pn.widgets.DatePicker(name='Select date range End', value=datetime(2020, 8, 31, tzinfo=timezone.utc))
interact_obj = interact(
make_plot,
Start=date_picker,
End=date_picker_2
)
return pn.Column(interact_obj).servable()