plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.58k stars 2.08k forks source link

rename the dcc.DatePickerSingle `date` property to `value` #1862

Open hannahker opened 2 years ago

hannahker commented 2 years ago

Is your feature request related to a problem? Please describe. Pattern-matching callbacks are really helpful when collecting a large number of inputs in a callback, using the value component property. For example, using the following as callback inputs works really well:

Input({"type": "param", "index": ALL}, "id"),
Input({"type": "param", "index": ALL}, "value"),

But, this is complicated when a date from dcc.DatePickerSingle is a parameter, because the name of the property holding its 'value' is actually called date. It's workable to just pass something like Input("start-date", "date") as a separate callback input, but makes for messy code and to some extent defeats the elegance of pattern-matching.

Describe the solution you'd like The component property from dcc.DatePickerSingle is called value instead of date.

Describe alternatives you've considered The workaround mentioned above is the alternative I've implemented. You could also have a dcc.Input where the user types in a date, but then you'd lose the nice calendar UI element.

ndrezn commented 2 years ago

I really like this idea. It's probably worth implementing a value param as an alias of date to keep this backwards compatible. Otherwise I frequently use that pattern with PMCs and it would be great to see value standardized across all formlikes.

alexcjohnson commented 2 years ago

I like it too. Yes, it would need to be done in a backward-compatible way for sure. And some logic around ensuring date and value stay in sync.

This could be extended to DatePickerRange as well, where value would be a length-2 list like it is for RangeSlider

ndrezn commented 2 years ago

@hannahker I vote you make a PR with this, great opportunity for Services to get familiar with core Dash libraries!

hannahker commented 2 years ago

Alright stay tuned! 😄

snehilvj commented 2 years ago

Hi @hannahker, you can try this out: https://dash-mantine-components.herokuapp.com/components/datepicker The docs are a work in progress but please reach out if you need any help.

PS: I'm the author of this library. Repo

hannahker commented 2 years ago

Hi @snehilvj - yes this is what I had in mind. Thanks for drawing this to my attention. These are also all really great looking components! Excited to try them out :)

troyscribner commented 1 year ago

As an alternative to Input("start-date", "date") as a workaround, you can add "value" to a custom class like this.

from dash import dcc

class DatePickerRangeCustom(dcc.DatePickerRange):

  def __init__(self, **kwargs):
    super(DatePickerRangeCustom, self).__init__(**kwargs)
    self.value = [kwargs['start_date'], kwargs['end_date']]
    self._prop_names.append('value')
    self.available_properties.append('value')