Creating a simple Range Slider in Bokeh
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)
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.
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.