Creating a Slider

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

import zero_true as zt
slider=zt.Slider(id='slider')

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

Slider Settings and Values

Sliders have a minimum, maximum, and step in zero-true. The default values are 0 and 100 but you can set them to whatever you’d like. The slider value will return an integer or a float depending on what it is set to.

print("The slider value divided by 2 is: "+str(slider.value/2.0))

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 
slider=zt.Slider(id='slider',min=1, max=100,label='Move the Slider to Filter the DataFrame')
#set the first value to 100 to keep all the novels in there
if not slider.value:
    slider.value=100

#display the dataframe with zero-true
zt.dataframe(id='df',df=novels_df[0:slider.value])

Customizing your 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.