Flask/Dash application running as a service in windows must be restarted every day to include the current day's date. How to solve the problem?

Issue

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.

Solution

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

Answered By – Mohamed Ait Ahmed

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published