I am working on dashboard that use a dropdown to select a csv file, and I want to use the min date from the csv file to DatePickerSingle min date, here is how I set the callback (just to give an idea)
Thank you! I realize what I want is to have the date picker to display the month of the minimum date of the csv, so that I can select a date that is in the csv file later. After a bit of fiddle,here is want I came up with:
import flask
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
from datetime import datetime as dt
server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server)
app.config['suppress_callback_exceptions'] = True
app.layout = html.Div([
html.Div(
dcc.Dropdown(
id='file_select',
options=[{'label':i, 'value':i} for i in range(10)])
),
html.Div(
dcc.DatePickerSingle(
id='date_select',
min_date_allowed=dt(2017, 1, 1),
max_date_allowed=dt.now()
)
)
])
@app.callback(Output('date_select', 'initial_visible_month'),
[Input('file_select', 'value')])
def update_picker(path):
df = pd.DataFrame().assign(date = pd.date_range(dt(2018,2,1), periods=10))
return df.date.min().to_pydatetime()
app.run_server()