Hi,
When I update bokeh version installed in my local computer, I keep getting the following error from Column Data Sources that I have defined inside a class.
Uncaught Error: reference {“id”:“1242”,“type”:“Div”} isn’t known (not in Document?)
When I install an earlier version of bokeh, the error appears to be resolved. But I don’t want to do that since I want some of the functionality which doesn’t exist in earlier versions. The original code is quite long, that’ s why you can find a very similar case below. The code I am sharing is not causing any problems, but the original one is problematic. Are there anyone facing the same problem?
Thanks.
from random import random
from bokeh.layouts import column
from bokeh.models import Button
from bokeh.palettes import RdYlBu3
from bokeh.plotting import figure, curdoc
from bokeh.models import ColumnDataSource
import copy
from functools import partial
from random import random
from threading import Thread
import time
from bokeh.models import ColumnDataSource
from bokeh.plotting import curdoc, figure
from tornado import gen
create a plot and style its properties
i = 0
count = 0
class Dummy:
def init(self):
self._data = ColumnDataSource(dict(x = [1],y=[0],text_color=[RdYlBu3[1%3]],text=[str(1)]))
dummy = Dummy()
def make_doc(doc):
doc = doc
p = figure(x_range=(0, 100), y_range=(0, 100), toolbar_location=None)
p.border_fill_color = ‘black’
p.background_fill_color = ‘black’
p.outline_line_color = None
p.grid.grid_line_color = None
add a text renderer to our plot (no data yet)p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color=“navy”, alpha=0.5)
r = p.text(x=“x”, y=“y”, text=“text”, text_color=“text_color”, text_font_size=“20pt”,
text_baseline=“middle”, text_align=“center”,source = dummy._data)
#p.add_glyph(source, glyph)
#ds = r.data_source
@gen.coroutine
def update(x, y,text,text_color):
dummy._data.stream(dict(x=x, y=y,text=text,text_color=text_color))
def blocking_task():
while True:
do some blocking computation
time.sleep(60)
global i
global count
dummyDict = copy.deepcopy(dummy._data.data)
if count == 0:
x = dummyDict[‘x’][0]
y = dummyDict[‘y’][0]
else:
x = i
y = i*2
print(x,“xi alabiliyo mu blocking”)
BEST PRACTICE — update .data in one step with a new dict
new_data = dict()
new_data[‘x’] =
new_data[‘y’] = [y]
new_data[‘text_color’] = [RdYlBu3[i%3]]
new_data[‘text’] = [str(i)]
doc.add_next_tick_callback(partial(update, x=new_data[‘x’], y=new_data[‘y’],text=new_data[‘text’],text_color=new_data[‘text_color’]))
count += 1
i = i + 1
print(i,“i”)
#but update the document from callback
create a callback that will add a number in a random location
def callback():
global i
global count
dummyDict = copy.deepcopy(dummy._data.data)
if count == 0:
x = dummyDict[‘x’][0]
y = dummyDict[‘y’][0]
else:
x = 2
y = 4
print(x,“xi alabiliyo mu callback”)
BEST PRACTICE — update .data in one step with a new dict
new_data = dict()
new_data[‘x’] = dummy._data.data[‘x’] +
new_data[‘y’] = dummy._data.data[‘y’] + [y]
new_data[‘text_color’] = dummy._data.data[‘text_color’] + [RdYlBu3[i%3]]
new_data[‘text’] = dummy._data.data[‘text’] + [str(i)]
dummy._data.data = new_data
count += 1
i = i + 1
add a button widget and configure with the call back
button = Button(label=“Press Me”)
button.on_click(callback)
doc.add_root(column(button, p))
thread = Thread(target=blocking_task)
thread.start()
print(dummy._data,“data itself”)
doc = curdoc()
make_doc(doc)