I am new at this and hoping for some guidance. I have data for a range of years, so using the DatePickerRange is quite clunky (it contains full calendars). Using two separate dropdowns for a year start_date and end_date also seems clunky. For this reason, I think a RangeSlider for the years in the dataset will be best. Here is what I started with for the DatePickerRange:
data["Year"] = pd.to_datetime(data["Year"], format="%Y")
data.sort_values("Year", inplace=True)
#Pulls min/max year from data for range params, user sets start and end date?
dcc.DatePickerRange(
id="date-range",
min_date_allowed=data.Year.min().date(),
max_date_allowed=data.Year.max().date(),
start_date=data.Year.min().date(),
end_date=data.Year.max().date(),
),
I am hoping to replace the above with this:
dcc.RangeSlider(
id='year-slider',
min=2011,
max=2019,
step=1.0,
value=[2011, 2019],
allowCross=False,
marks={
2011: '2011',
2012: '2012',
2013: '2013',
2014: '2014',
2015: '2015',
2016: '2016',
2017: '2017',
2018: '2018',
2019: '2019'
},
For the callbacks, there are sections I am really having trouble with. How do I return the user input from the RangeSlider? I’ve added questions in the comments.
@app.callback(
[Output("PIT-chart", "figure")],
[
Input("region-filter", "value"),
Input("type-filter", "value"),
#Attempting to replace the below two lines with values from RangeSlider
Input("date-range", "start_date"),
Input("date-range", "end_date"),
#Does RangeSlider return a list, and how does it function here?
#Since there are no 'options' in RangeSlider, what is the 'value'?
#Input("year-slider","value"),
],
)
#Need to replace start_date and end_date with user values from RangeSlider
def update_charts(region, Homeless_Type, start_date, end_date):
mask = (
(data.region == region)
& (data.Homeless_Type == Homeless_Type)
#Need to return the min and max from dcc.RangeSlider to the data.Year values below
& (data.Year >= start_date)
& (data.Year <= end_date)
)
filtered_data = data.loc[mask, :]