Reputation: 21
I would like to use a Bokeh slider widget to show a list of month or a list of text instead of integer. E.g. Nov 2018, Dec 2018, Jan 2019, Feb 2019..... Is it possible?
Many Thanks
Upvotes: 1
Views: 779
Reputation: 1481
Just to elaborate on what @bigreddot described:
from bokeh.models import CustomJS, Slider, Legend, Div
from bokeh.layouts import column
from bokeh.plotting import ColumnDataSource, show, output_file
div = Div(text= '<b>text0</b>', style={'font-size': '150%', 'color': 'blue'})
str_list = ['text0', 'text1', 'text2']
str_slider = Slider(start=0, end=len(str_list)-1, value=0, step=1, title="string")
callback = CustomJS(args=dict(div=div, str_list = str_list, str_slider=str_slider),
code="""
const v = str_slider.value
div.text = str_list[v]
""")
str_slider.js_on_change('value', callback)
layout = column(str_slider, div)
output_file('test.html')
show(layout)
Upvotes: 2
Reputation: 34628
As of Bokeh 1.3.4 Slider widget text is not configurable. Adding a hook for a formatter seems like a reasonable ask (and also a good task for a first-time contributor), so a Github Issue would be appropriate.
For now, you could put the slider in column
with a Div
and update the text
property of the div with a CustomJS
callback (or a Python callback, if this is a Bokeh server app).
Upvotes: 1