Hiya, hopefully I’ll be able to describe this adequately!
I’m working on a way to use Bokeh to make an interactive data analysis tool: GitHub - 0Hughman0/htools
I’ve worked out how to make custom Python ‘dataclasses’ that I can use in Python and then use in JS callbacks e.g.:
from bokeh.models.widgets.buttons import Button
from bokeh.models.callbacks import CustomJS
from bokeh.core.properties import String
from bokeh.core.has_props import HasProps
from bokeh.io import output_notebook, show
output_notebook()
class DataClass(HasProps):
text = String(default='Default')
d = DataClass()
d.text = "Hello"
b = Button(label='Do')
b.js_on_click(CustomJS(code="window.alert(d.text);", args={'d': d}))
show(b)
So clicking the button, ‘Hello’ will pop up as expected.
However subsequently running:
d.text = 'Goodbye'
and then clicking the button, rather than ‘Goodbye’ popping up, ‘Hello’ still appears.
This is problem for me because I want the callback to keep track of the current state of my Python objects, and look this up every time I click a button. Thing is as far as I can tell, passing Bokeh models as callbacks the current state of the model is used rather than this seemingly cached value.
Perhaps I’m barking up the wrong tree, and help or advice would be appreciated! (I’d also like to know how you guys test code that is both written in JS and for Jupyter notebooks!)
Using Bokeh ‘1.2.0’ and Jupyter ‘4.4.0’.