Creating a Range Slider

Creating a rage slider in zero-true is simple. Type:

import zero-true as zt
range_slider=zt.RangeSlider(id='slider')

Run the cell in your notebook, and watch the range slider appear below.

Range Slider Settings and Values

Range Sliders have a minimum, maximum, and step in zero-true. The default values for min and max are 0 and 100 and the step is 1 but you can set them to whatever you’d like. The range slider value will return a list structured as follows [min,max]. Here is a little snippet to show you how to access the min and max values from your range slider.

max = range_slider.value[0]
min = range_slider.value[1]

print("Min val is "+str(min)+ " and max val is "+str(max))

Range Slider Use Cases

Sliders can be used to capture any numeric input. Here is a more fleshed out example including filtering a dataframe:

import pandas as pd 
import zero_true as zt 

novels_df = pd.read_html("https://en.wikipedia.org/w/index.php?title=Science_Fiction:_The_100_Best_Novels&oldid=1091082777", match='The 100 Best Novels')[0]

#define a slider in zero-true to filter the data 
range_slider=zt.RangeSlider(id='range_slider',min=1, max=100,label='Move the Slider to Filter the DataFrame')
if not range_slider.value:
    range_slider.value=[0,100]
zt.dataframe(id='df',df=novels_df[range_slider.value[0]:range_slider.value[1]])

![title](/blogs/gifs/range slider.gif)

Customizing your Range Slider

You can also add different colors and labels to your slider to make it to your liking. Feel free to check out the full range of options with the api reference for a slider.