Bokeh callback for image update

情到浓时终转凉″ 提交于 2019-12-11 23:47:16

问题


I have a Bokeh plot that can display an image, which can be changed by a slider (and also should update regularly) (similar to this question Sliding through images with Bokeh Slider). So the url of the image changes and Bokeh reloads the image. Is there a way to attach a callback function to the load of the image?


回答1:


As of Bokeh 1.4.0 there is no callback on the image load. The ImageURL glyph is not one that is much used by the core developers, AFAIK, and we can't always anticipate every use case that every user might want. For this reason, we have made Bokeh itself extensible, so the best I can suggest at the moment is to extend Bokeh with a custom extension. The documentation for creating custom extensions is here:

http://docs.bokeh.org/en/latest/docs/user_guide/extensions.html

In abbreviated forms, you'd create a class like this that adds a callback property, and supplies the JavaScript implementation for your custom ImageURL glyph:

class MyImageURL(ImageURL):

     callback = Instance(Callback, help="A callback to run when images load")

    __implementation__ = JAVASCRIPT_CODE_HERE

Then it can be used like any low level glyoh:

my_glyph = MyImageURL(...)
source = ColumnDataSource(...)
plot.add_glyph(source, my_glyph)



回答2:


You can subscribe to the change event of the image tag and do whatever you need to. You can do this with JQuery's change method or straight javascript's onchange handler.



来源:https://stackoverflow.com/questions/40696216/bokeh-callback-for-image-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!