ValueError when updating ticks property of a bokeh FixedTicker object

Developed a server app where the ticks property of a FixedTicker object was meant to be updated in a callback. This produced an unexpected ValueError. Found that just creating a new FixedTicker object each time the callback is executed works, but that does not seem to be best coding practice for bokeh! Here is a minimal example. As-is it works on the first iteration only (loading the app). When Button is pressed a ValueError triggers when the ticks property is updated. Otherwise the minimal example can be made to work by creating a new FixedTicker object at each iteration (uncomment line 16, comment line 15). Not sure if this a bug or feature…

import numpy as np
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, FixedTicker, Button
from bokeh.layouts import row
from bokeh.io import curdoc

src = ColumnDataSource()
fig = figure(width=600, height=200)
fig.xaxis.ticker = FixedTicker()
fig.circle('x', 'y', source=src)

def update():
    n = np.random.choice(range(2, 20))
    src.data = {'x': np.arange(n), 'y': np.arange(n) ** 2}
    fig.xaxis.ticker.ticks = np.arange(n) # update existing FixedTicker
    # fig.xaxis.ticker = FixedTicker(ticks=np.arange(n)) # create new FixedTicker

button = Button()
button.on_click(update)

update()
curdoc().add_root(row(button, fig))

The property type for ticks is Seq(float) which expects a Python list or tuple

fig.xaxis.ticker.ticks = list(np.arange(n))

I’m not sure why it works on initialization but I would say that is accidental. Perhaps it could be made to work with NumPy arrays being officially supported, but no one has ever asked about it that I can recall.

Confirmed, that was the issue. Thanks for the response and support!

1 Like

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