I have this Flask/Dash application that I deployed as a service running in the background and it works fine. I use a datepicker (calendar) in the application to choose the date for which the data will be fetched and processed. However, the date of today is being grayed (deactivated) every day until I restart the service. I am using this :
from dash import dcc
dcc.DatePickerSingle(id='previ_date',
min_date_allowed=datetime.date(2022, 5, 10),
max_date_allowed=datetime.date.today(),
initial_visible_month=datetime.date.today(),
date=datetime.date.today())
Normally, the max_date_allowed argument is set to today's date, however, it doesn't behave as expected. Any help on how to overcome this issue is appreciated.
CodePudding user response:
Eventually, I solved the issue as recommended by @coralvanda by setting the initial value as None, then doing the checking and updating inside a callback function.
dcc.DatePickerSingle(id='previ_date',
min_date_allowed=datetime.date(2022, 5, 10),
max_date_allowed=None,
initial_visible_month=None,
date=datetime.date.today())
@app.callback([Output("previ_date", "max_date_allowed"), Output("previ_date", "initial_visible_month")],
[Input("previ_date", "max_date_allowed"), Input("previ_date", "initial_visible_month")])
def update_date(max_date, current_month):
if max_date==None:
max_date=datetime.date.today()
if current_month==None:
current_month=datetime.date.today()
return max_date, current_month