I am making a bubble chart using Bokeh and I'd like to be able to update my plot's x_range, as it can be used for either integers or strings.
If I'm not mistaken, Int ranges will be managed through Range1d
and string ones through FactorRange
.
I'm trying to do it using the update() function, called whenever a control is used:
plot = figure(y_range=FactorRange(factors=pandata['HostnameIP'].tolist()), plot_height=600, plot_width=700, title="Visualization", toolbar_location="above", tools=[hover, BoxSelectTool(), ResetTool()])
plot.circle(x='x', y='y', source=source, size=7, color="color", line_color=None, fill_alpha="alpha")
controls = [malware, compromise, x_axis]
for control in controls:
control.on_change('value', lambda attr, old, new: update())
def update():
df = select_units()
x_name = axis_map[x_axis.value]
plot.xaxis.axis_label = x_axis.value
if x_name == 'Malware':
plot.x_range=FactorRange(factors=pandata['Malware'].tolist())
l.children[0].children[1] = plot
# [...]
inputs = widgetbox(*controls, sizing_mode=sizing_mode)
l = layout([
[inputs, plot],
[data_table]
], sizing_mode=sizing_mode)
update()
curdoc().add_root(l)
curdoc().title = "Visualization"
According to this SO, this technique should be working, but I'm getting a blank plot instead.
I've also tried this answer, but it looks like figure.set() doesn't exist anymore.
Any ideas on how to do that? I'm still discovering Bokeh.
TYA :)