# Callbacks for range from RangeSlider

**URL:** https://community.plotly.com/t/callbacks-for-range-from-rangeslider/50992
**Category:** Dash Python
**Created:** [March 13, 2021, 11:02pm UTC](https://community.plotly.com/t/callbacks-for-range-from-rangeslider/50992 "2021-03-13T23:02:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![SlappyMcWhite](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@SlappyMcWhite](https://community.plotly.com/u/SlappyMcWhite)
#### Post date: [March 13, 2021, 11:02pm UTC](https://community.plotly.com/t/callbacks-for-range-from-rangeslider/50992/1 "2021-03-13T23:02:49Z")

</div>

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:

```auto
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:

```auto
					    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.

```auto
@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, :]

```

---

<div class="post-metadata">

### Author: ![Eduardo](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/eduardo/32/13310_2.png) [@Eduardo](https://community.plotly.com/u/Eduardo)
#### Post date: [March 13, 2021, 11:33pm UTC](https://community.plotly.com/t/callbacks-for-range-from-rangeslider/50992/2 "2021-03-13T23:33:49Z")

</div>

Hi @SlappyMcWhite

The input in your callback must be:

```auto
Input("year-slider", "value"),

```

The property “value” of the id “year-slider” has two elements, the first is the start year selected by the user and the second is the year end selected:

```auto
start_selected = value[0]
end_selected = value[1]

```
