Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Creating a simple Range Slider in Bokeh

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The range slider widget allows you to select a floating-point range from a slider with start and endpoints. The Bokeh widget RangeSlider consists of start and end values, a step size, an initial value, and a title. 


range_slider = RangeSlider(start, end, value, step, title)

range_slider.js_on_change(“value”, CustomJS(code))

Let us look at the procedure for creating a range slider.

  • Import the RangeSlider widget from bokeh.models

In this step, we are importing figures and show methods from bokeh.plotting interface. Bokeh.plotting interface allows you to create plots by assembling various elements such as grid, axis, and other tools. The figure() method allows you to add different types of glyphs to your plot and show() method allows you to display your visualization in a browser. Similarly, we import layout from bokeh.layouts to create layout objects. And finally, we are importing RangeSlider to create a range slider and make our visualization interactive.

  • Setting up the data and the figure.

In this step, we are creating an output file which is an HTML file, and opens up in the new window in your browser. The output will be displayed in this HTML file. The figure method creates a figure with the given range, height, and width.

  • Create a RangeSlider Object


RangeSlider(title, start, end, step, value)


  • Title: It represents the title of the range slider.
  • Start: It represents the range’s lower bound and is of type float.
  • end: It represents the range’s upper bound and is of type float.
  • step: It represents the interval between the values and is of type float.
  • value: It represents a tuple that contains the values of upper and lower bounds of the selected range.
  • Link to the JavaScript 

The link to the javaScript is given by using the link_js() function to link the values generated by the RangeSlider to your plot. 


RangeSliderObject.js_link(value, p.x_range, start/end, attr_selector)

  • Creating a layout of all the elements you want to display on the browser.

Finally, we are using the layout method to display all the elements of our dashboard and show(layout) to display our layout in the browser.



from bokeh.plotting import figure, show
from bokeh.layouts import layout
from bokeh.models import RangeSlider
x = list(range(12))
y = [i**2 for i in x]
output_file = ('range_slider.html')
p = figure(x_range=(1, 9), plot_width=600, plot_height=300)
points =, y=y, size=40, fill_color="red")
range_slider = RangeSlider(
    title=" Adjust X-Axis range",
    value=(p.x_range.start, p.x_range.end),
range_slider.js_link("value", p.x_range, "start", attr_selector=0)
range_slider.js_link("value", p.x_range, "end", attr_selector=1)
layout = layout([range_slider], [p])


My Personal Notes arrow_drop_up
Last Updated : 29 Jun, 2021
Like Article
Save Article
Similar Reads
Related Tutorials