Good Evening All!
I have been working on my web app (A dashboard for displaying sports science/medicine metrics to coaches that I work with). Right now I am trying to switch from using the included datepicker to using a dropdown that has preselected values that correspond with custom date ranges (past 4 weeks, 3 months, 6 months, year, 4 years). This is being done to modify a plotly scatter plot that is showing a specific athlete’s body weight over time.
I created variables that have these date ranges calculated like so (I just started learning to program in late April so please be ready to cringe…):
today = datetime.date.today()
four_weeks= timedelta(weeks = 4)
three_months = timedelta(weeks = 12)
six_months = timedelta(weeks = 24)
twelve_months = timedelta(weeks = 48)
four_years = timedelta (weeks = 192)
month_ago = today - four_weeks
three_months_ago = today - three_months
six_months_ago = today - six_months
one_year_ago = today - twelve_months
four_years_ago = today - four_years
I then wanted to create “values” in my dropdown that would be connected to these?
I have my callback setup like this currently:
@app.callback(
Output(body_weight_graph, ‘figure’),
Output(mytitle, ‘children’),
Input(dropdown, ‘value’),
Input(weight_drop, ‘value’)
)def update_graph(column_name, start_date):
print(column_name)
print(type(column_name))
dff = df[(df[‘Name’] == column_name)]
dff = dff[([‘Date’] <= today) & (dff[‘Date’] >= start_date)]
fig = px.line(data_frame=dff, x=‘Date’, y=[‘Weight’, ‘Goal’],
color_discrete_map={‘Weight’: “blue”, “Goal”: “green”}, markers=True, template=‘plotly_dark’, title=“Weight Progress over Time”)return fig, '# '+column_name
and here is my current dropdown setup…I deleted what I had for values on the weight_drop dropdown because I kept on just making strings that weren’t connected to the first set of variables (which are global variables right now instead of local).
mytitle = dcc.Markdown(children=‘’)
body_weight_graph = dcc.Graph(id=‘body_weight_graph’, figure={})
dropdown = dcc.Dropdown(id=‘dropdown_1’, options=df.Name.unique(), value=‘John Doe’, clearable=False)
weight_drop = dcc.Dropdown(id=‘weight_dropdown’, options=‘’, value=‘’, clearable=False)
Does anyone have any general direction to point me in for something like this? I am just assuming this is an easy solution and this is a dumb question to be asking…