infinitely_improbable
infinitely_improbable

Reputation: 499

Bokeh - How to Change Glyph Attribute in JS Callback?

I'm making a plot in Bokeh 0.13.0, and I want to change the x attribute of a Ray glyph in a custom JS callback.

I need to know 2 things:

  1. How do I pass the Glyph into the callback?
  2. How do I reference the x attribute once it's been passed?

Here's the gist:

vline = Ray( x=vline_x, y=0, length=0, angle=1.5708, line_width=1)
plot.add_glyph(source, vline)

callback = CustomJS(args=dict(source=source), code="""
    var data = source.data;

    // CHANGE ATTRIBUTE HERE

    source.change.emit();
""")

Thanks in advance!

Upvotes: 1

Views: 570

Answers (1)

infinitely_improbable
infinitely_improbable

Reputation: 499

Figured it out. I passed the GlyphRenderer object for the Ray as an item in the CustomJS args dict. I was then able to access the Glyph object for the Ray and was able to change its attributes from there.

Might also have worked if I'd just passed the Glyph object in the first place, but oh well.

Updated code:

vline = plot.add_glyph(
    source,
    Ray(x=vline_x,y=0, length=0, angle=1.5708, line_width=1)
)

callback = CustomJS(args=dict(vline=vline, source=source), code="""

    vline.glyph.x = <new_value>;

    source.change.emit();
""")

Upvotes: 1

Related Questions