FloatSlider - custom formatter from radians to degrees

Usually I format my FloatSlider with a PrintfTickformatter, for example:

from bokeh.models.formatters import PrintfTickFormatter
formatter = PrintfTickFormatter(format="%.3f")
float_slider = pn.widgets.FloatSlider(name='Float Slider', start=0, end=3.141, step=0.005, value=1.57, format=formatter)
float_slider

Currently I’m dealing with many FloatSlider representing angles in radians. Is there a way to show the value in degrees? I thought I could subclass PrintfTickformatter, however there is a lot of abstraction in Bokeh’s source code, hence I could not find a way to achieve that.

Is this what you want?

from bokeh.models.formatters import FuncTickFormatter
formatter = FuncTickFormatter(code="""
    return (180./3.1415926 * tick).toFixed(2)
""")

float_slider = pn.widgets.FloatSlider(name='Float Slider', start=0, end=3.141, step=0.005, value=1.57, format=formatter)
float_slider
1 Like

Thank you, that’s perfect! :slight_smile:

1 Like