So there’s an existing dashboard that I am adding a feature to. Is a single, simple filter but it breaks the existing dashboard somehow.
# ------------------------------------------------
# This is the graphics aspect of it
html.P(
"Campaign Periods"
),
dcc.Dropdown(
id = 'campaign-dropdown',
options = [
#! would it be easier to modify the MariaDB table?
{'label': "Q3 2020", 'value': "Q3 2020"},
{'label': "Q4 2020", 'value': "Q4 2020"},
{'label': "Q1 2021", 'value': "Q1 2021"},
{'label': "Q2 2021", 'value': "Q2 2021"},
{'label': "Q3 2021", 'value': "Q3 2021"},
{'label': "Q4 2021", 'value': "Q4 2021"}
],
#value = "Q2 2021",
multi = False,
placeholder = 'Select Campaign',
),
# ------------------------------------------------
#This is the callback to update the campaign filter
@app.callback(
[Output('date-range-picker', 'start_date'), Output('date-range-picker', 'end_date')],
[Input('campaign-dropdown', 'value')]
)
def update_campaign(value):
# Initial Dummy values because of an error (because checking for start before assigning), might do this in an else statement below
if(value == 'Q3 2020'):
start = datetime.date(2020, 7, 1)
end = datetime.date(2020, 9, 30)
elif(value == 'Q4 2020'):
start = datetime.date(2020, 10, 1)
end = datetime.date(2020, 12, 31)
elif(value == 'Q1 2021'):
start = datetime.date(2021, 1, 1)
end = datetime.date(2021, 3, 31)
elif(value == 'Q2 2021'):
start = datetime.date(2021, 4, 1)
end = datetime.date(2021, 6, 30)
elif(value == 'Q3 2021'):
start = datetime.date(2021, 7, 1)
end = datetime.date(2021, 9, 30)
elif(value == 'Q4 2021'):
start = datetime.date(2021, 10, 1)
end = datetime.date(2021, 12, 31)
else:
start = datetime.date(2020, 7, 1)
end = datetime.date.today()
# Ensuring Valid Dates
if(start > datetime.date.today()):
start = datetime.date.today()
if(start < datetime.date(2020, 7, 1)):
start = datetime.date(2020, 7, 1)
if(end > datetime.date.today()):
end = datetime.date.today()
if(end < datetime.date(2020, 7, 1)):
end = datetime.date(2020, 7, 1)
return(start, end)
So initially I did not know you couldn’t output from two different callbacks to a single component, but after testing it locally on my machine I got the error messages and solved that.
However I am still facing a boatload of other errors that shouldn’t happen since all I change is start_date
and end_date
. For example some of the issues I am facing at the moment are:
ValueError: Bin edges must be unique: array([nan, nan, nan, nan]). You can drop duplicate edges by setting the 'duplicates' kwarg
raise DataError("No numeric types to aggregate") pandas.core.base.DataError: No numeric types to aggregate