2

Using some code I found on this question, I managed to update the columns for the graph I am making. The problem is, I am only allowed to make ONE update and then no more effect afterwards. The same problem happens when executing the code from the reference question. I will post a snippet here just for convenience:

import bokeh
import bokeh.plotting
p = bokeh.plotting.figure(x_range=(0,4), y_range=(0,4), plot_height=200 )
csource = bokeh.models.ColumnDataSource(data=dict(
        x=[1,2,3],
        y=[1,2,1],
        colors1=["#ff0000","#00ff00","#0000ff"],
        colors2=["#ff00ff","#ffff00","#00ffff"]))
cir = p.circle(x="x",y="y",fill_color="colors1",line_color="colors1",
               size=20,source=csource)
cb_cselect = bokeh.models.CustomJS(args=dict(cir=cir,csource=csource), code ="""
    var selected_color = cb_obj.value;
    cir.glyph.line_color.field = selected_color;
    cir.glyph.fill_color.field = selected_color;
    csource.trigger("change")
""")
color_select = bokeh.models.Select(title="Select colors", value="colors1", 
                    options = ["colors1","colors2"], callback = cb_cselect)
layout = bokeh.layouts.gridplot([[p],[color_select]])
bokeh.io.output_file("output.html")
bokeh.io.show(layout)

Basically, I run the code, the html file opens in my browser, I update via the dropdown, then click Reset before any changes can take effect. Afterwards, no more changes are possible unless I refresh my browser. It didn't seem like other users were having this issue, so I'm quite confused as to why this is happening. Also, I apologize, I would have simply commented on that question but I don't have the necessary reputation as of yet.

Camper731
  • 83
  • 6

1 Answers1

1

The syntax for signaling events in BokehJS changed some time back. Additionally, it's the glyph you are changing, so that you should be emitting a change signal. Here is a version of the callback that works:

cb_cselect = bokeh.models.CustomJS(args=dict(cir=cir,csource=csource), code ="""
    var selected_color = cb_obj.value;
    cir.glyph.line_color.field = selected_color;
    cir.glyph.fill_color.field = selected_color;
    cir.glyph.change.emit()
""")
bigreddot
  • 33,642
  • 5
  • 69
  • 122