I am creating a dashboard using Plotly Dash that requires data to be filtered by date (sliders don't work since some charts are categorical).
I would like to allow the user to input a date which I would then use as a global variable. I import this global variable to filter my dataframes in other python files, and then create the charts. My attempt below doesn't work; the variable start_date
does not update.
app = dash.Dash()
app.layout = html.Div([
dcc.Input(id='date', value='start date (yyyy-mm-dd)', type='text'),
html.Button(id='submit-button', type='submit', children='Submit'),
html.Div(id='output_div')
])
start_date = 0
@app.callback(Output('output_div', 'children'),
[Input('submit-button', 'n_clicks')],
[State('date', 'value')],
)
def update_output(clicks, input_value):
if clicks:
print(clicks, input_value)
global start_date
start_date = datetime.strptime(input_value, '%Y-%m-%d').date()
return start_date
print(type(start_date))
if __name__ == '__main__':
app.run_server(debug=True, port=8051)