Escaping Characters on RangeSlider 'format'

I tried searching in the documentation but didn’t get anywhere with this question.
What “format standard” is the format option for RangeSlider?

yield_slider = RangeSlider(
            start=0.1, 
            end=5,
            value=(0.1, 5),
            format='0.00 \%',
            title="Yield"
)

I’m trying to get:
0.10%..5.00%

However, format takes ‘%’ and formats it as a percentage so I get:
10%..500%

What is the correct way to escape special characters like the percent symbol?
I’ve tried the obvious ones ‘%%’ and ‘%’ to no avail.

By default, ranges use the NumeralTickFormatter, which documents all of its formats in the reference guide: formatters — Bokeh 3.2.0 Documentation

Under the covers, NumeralTickFormatter just passes everthing to a JavaScript library numbro.js. Looking at their docs, I am not sure that any escaping is supported.

However, besides format strings, you can pass any actual tick formatter objects, e.g. a PrintfTickFormatter might be a better choice here:

https://docs.bokeh.org/en/latest/docs/user_guide/styling/plots.html#tick-label-formats

Thanks, that’s very helpful.
PrintfTickFormatter is the best solution given I have the ability to use all of the printf functionality

So I think we can close this except for one note for people looking at this thread later.
Just due to the limitations of PrintfTickFormatter and NumeralTickFormatter, if you want to escape a character AND use the thousands separator, I don’t think there is a supported way to print this.

For example, if you want 2560 to become 2,560 minutes you’ll either have to go with:

NumeralTickFormatter(format='0,000')="2,560"
PrintfTickFormatter(format='%.0f minutes') = "2560 minutes"

So in this rare case, making a custom class might be necessary.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.