TypeError: Object of type 'function' is not JSON serializable

I have following code:
TypeError: Object of type ‘function’ is not JSON serializable

source = ColumnDataSource(val_df)

p0 = figure(
    x_axis_type="datetime",
    x_axis_label="Timestamp",
    title="Spans",
)

p0.yaxis.axis_label = 'score'
p0.y_range==Range1d(start=0, end=1)

f = figure(plot_width=1200, plot_height=500,x_axis_type="datetime",x_axis_label="Timestamp")
r1 = f.line(
x='timestamp', #Column timestamp
y=df.columns[5], #Frequency column
source=source,
)

handler = CustomJS(
args=dict(
figure=figure,
),
code = """
var name = cb_obj.value;
"""

select = Select(title="Select tags:", value='1', options=list(df.columns)[1:])
select.js_on_change('value', handler)

show(column(select, p0))
)

I get the error as in the title while running the show command. What is wrong here ?

Here:

handler = CustomJS(
args=dict(
figure=figure,
),

You’re passing the bokeh figure model itself into the callback. A few lines up you created an instance of one with ‘f = figure(…your args etc…)’. You need to pass the specific instance to CustomJS, not the model:

handler = CustomJS(
args=dict(
f=f #now in the 'code' arg f will point to the figure instance f
# figure=figure,
),
2 Likes

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