Add Interactive Slider to Bokeh Plots
Bokeh is an interactive Data visualization library of Python. It can be used to create interactive plots, dashboards, and data applications. Widgets are nothing but additional visual elements that you can add to your plots to interactively control your Bokeh document. There are various types of widgets such as button, div, spinner, slider, etc. In this article, we will learn about the slider widget in bokeh.
The Bokeh slider can be configured with start and end values, a step size, an initial value, and a title. Basically, you need to import the Slider widget from bokeh.models.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
from bokeh.models import CustomJS, Slider
Slider() function can be used to create a slider.
Slider(start=0, end=10, value=1, step=.1, title=”Stuff”)
- start: It represents the sliders starting value.
- end:It represents the sliders ending value.
- value: It represents the current value of the slider.
- step: It represents the interval through which the slider moves.
- title: It represents the title of the slider widget.
Now add callback functionality using CustomJS which is called when on_change event occurs.
js_on_change(“value”, CustomJS(code=”””…. “””))
js_on_change is a callback function that is called when slider on_change event occurs. and customJS(code=””” “””) represents the code that is to be executed once the event occurs. Now call the callback function using the slider object and create a layout of all the elements you want to display on the browser.
Example: Creating a slider using bokeh