CustomJS callback for reset tool

Hi,

I have CustomJS calback attached to a datasource that I use to recompute an average whenever the selection changes.

http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-model-property-events

self.pcircle.data_source.on_change(‘selected’, self.calculate_avg_temp)

def calculate_avg_temp(self, attr, old, new):
index = new[‘1d’][‘indices’]
if len(index) == 0:
return
index.sort()
self.update_ave_temp(np.mean(np.array(self.cds.data[‘temperatures’])[index]))

and it works fine.

Then I would like to clear the selection and reset the average value.

Can I use a CustomJS callback for the plot reset tool? is there an example for that? or do you recommend another method.

thank you,

···

Angelo Fausti

So, the following code works, I managed to update the Div text property
when the plot reset tool is used. But I am getting this error in the JS
console:

document.js:412 Uncaught Error: reference
{"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not
in Document?)

why is that?

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.models.widgets import Div
from bokeh.layouts import widgetbox, column

title = Div(text="")

plot = figure()

callback = CustomJS(args={'title': title}, code="""title.text='Reset event
ocurred.'""")

plot.js_on_event('reset', callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

I would like to do something similar in my bokeh application that's why I
am running with bokeh server.

Bokeh version 0.13.0

thanks,

Angelo Fausti

···

On Fri, Jul 20, 2018 at 2:51 PM, Angelo Fausti <[email protected]> wrote:

Hi,

I have CustomJS calback attached to a datasource that I use to recompute
an average whenever the selection changes.

http://bokeh.pydata.org/en/latest/docs/user_guide/
interaction/callbacks.html#customjs-for-model-property-events

self.pcircle.data_source.on_change('selected', self.calculate_avg_temp)

def calculate_avg_temp(self, attr, old, new):
    index = new['1d']['indices']
    if len(index) == 0:
        return
    index.sort()
    self.update_ave_temp(np.mean(np.array(self.cds.data['
temperatures'])[index]))

and it works fine.

Then I would like to clear the selection and reset the average value.

Can I use a CustomJS callback for the plot reset tool? is there an example
for that? or do you recommend another method.

thank you,

Angelo Fausti

So, the error I had before

document.js:412 Uncaught Error: reference {“id”:“58779667-2eb0-40c1-ab52-d3b1928cd2a0”,“type”:“Div”} isn’t known (not in Document?)

happens at

plot.js_on_event(‘reset’, callback)

as the message suggests I tried to configure the callback after adding the Div widget to the bokeh document, like this:

But then I get another error in the JS console:

connection.js:178 [bokeh] Failed to repull session Error: reference {“id”:“338aa405-4f2e-4292-b044-a63141bd2c38”,“type”:“CustomJS”} isn’t known (not in Document?)

and this time the app does not show up in the browser.

In both cases I’m running the server with --log-level debug but there’s nothing in the bokeh server logs.

$ bokeh serve --log-level debug app.py

I would appreciate any help to understand what is going on.

thanks,

···

from bokeh.io import curdoc

from bokeh.plotting import figure

from bokeh.models.callbacks import CustomJS

from bokeh.models.widgets import Div

from bokeh.layouts import widgetbox, column

title = Div(text=“”)

plot = figure()

callback = CustomJS(args={‘title’: title}, code=“”“title.text=‘Reset event ocurred.’”“”)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

plot.js_on_event(‘reset’, callback) # moved this line to here

On Fri, Jul 20, 2018 at 5:03 PM, Angelo Fausti [email protected] wrote:

Angelo Fausti

So, the following code works, I managed to update the Div text property when the plot reset tool is used. But I am getting this error in the JS console:

document.js:412 Uncaught Error: reference {“id”:“58779667-2eb0-40c1-ab52-d3b1928cd2a0”,“type”:“Div”} isn’t known (not in Document?)

why is that?

thanks,

from bokeh.io import curdoc

from bokeh.plotting import figure

from bokeh.models.callbacks import CustomJS

from bokeh.models.widgets import Div

from bokeh.layouts import widgetbox, column

title = Div(text=“”)

plot = figure()

callback = CustomJS(args={‘title’: title}, code=“”“title.text=‘Reset event ocurred.’”“”)

plot.js_on_event(‘reset’, callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

I would like to do something similar in my bokeh application that’s why I am running with bokeh server.

Bokeh version 0.13.0

Angelo Fausti

On Fri, Jul 20, 2018 at 2:51 PM, Angelo Fausti [email protected] wrote:

Hi,

I have CustomJS calback attached to a datasource that I use to recompute an average whenever the selection changes.

http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-model-property-events

self.pcircle.data_source.on_change(‘selected’, self.calculate_avg_temp)

def calculate_avg_temp(self, attr, old, new):
index = new[‘1d’][‘indices’]
if len(index) == 0:
return
index.sort()
self.update_ave_temp(np.mean(np.array(self.cds.data[‘temperatures’])[index]))

and it works fine.

Then I would like to clear the selection and reset the average value.

Can I use a CustomJS callback for the plot reset tool? is there an example for that? or do you recommend another method.

thank you,

Angelo Fausti

$ bokeh serve --log-level debug app.py

with bokeh 0.13.0

thanks,

Angelo Fausti

So, the error I had before

document.js:412 Uncaught Error: reference {“id”:“58779667-2eb0-40c1-ab52-d3b1928cd2a0”,“type”:“Div”} isn’t known (not in Document?)

happens at

plot.js_on_event(‘reset’, callback)

as the message suggests I tried to configure the callback after adding the Div widget to the bokeh document, like this:

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.models.widgets import Div
from bokeh.layouts import widgetbox, column

title = Div(text=“”)

plot = figure()

callback = CustomJS(args={‘title’: title}, code=“”“title.text=‘Reset event ocurred.’”“”)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

plot.js_on_event(‘reset’, callback) # moved this line to here

But then I get another error in the JS console:

connection.js:178 [bokeh] Failed to repull session Error: reference {“id”:“338aa405-4f2e-4292-b044-a63141bd2c38”,“type”:“CustomJS”} isn’t known (not in Document?)

and this time the app does not show up in the browser.

In both cases I’m running the server with --log-level debug but there’s nothing in the bokeh server logs.

$ bokeh serve --log-level debug app.py

I would appreciate any help to understand what is going on.

thanks,

Angelo Fausti

So, the following code works, I managed to update the Div text property when the plot reset tool is used. But I am getting this error in the JS console:

document.js:412 Uncaught Error: reference {“id”:“58779667-2eb0-40c1-ab52-d3b1928cd2a0”,“type”:“Div”} isn’t known (not in Document?)

why is that?

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.models.widgets import Div
from bokeh.layouts import widgetbox, column

title = Div(text=“”)

plot = figure()

callback = CustomJS(args={‘title’: title}, code=“”“title.text=‘Reset event ocurred.’”“”)

plot.js_on_event(‘reset’, callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

I would like to do something similar in my bokeh application that’s why I am running with bokeh server.

Bokeh version 0.13.0

thanks,

Angelo Fausti

Hi,

I have CustomJS calback attached to a datasource that I use to recompute an average whenever the selection changes.

http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-model-property-events

self.pcircle.data_source.on_change(‘selected’, self.calculate_avg_temp)

def calculate_avg_temp(self, attr, old, new):
index = new[‘1d’][‘indices’]
if len(index) == 0:
return
index.sort()
self.update_ave_temp(np.mean(np.array(self.cds.data[‘temperatures’])[index]))

and it works fine.

Then I would like to clear the selection and reset the average value.

Can I use a CustomJS callback for the plot reset tool? is there an example for that? or do you recommend another method.

thank you,

Angelo Fausti

Update: I think what I am seeing

document.js:412 Uncaught Error: reference {“id”:“58779667-2eb0-40c1-ab52-d3b1928cd2a0”,“type”:“Div”} isn’t known (not in Document?)

is related to this issue

https://github.com/bokeh/bokeh/issues/7970

and similar errors are seen in the js_events.py example at https://github.com/bokeh/bokeh/blob/master/examples/howto/

Anyways, the code to reproduce it is:

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.models.widgets import Div
from bokeh.layouts import widgetbox, column

title = Div(text=“”)

plot = figure()

callback = CustomJS(args={‘title’: title}, code=“”“title.text=‘Reset event ocurred.’”“”)

plot.js_on_event(‘reset’, callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

Run as

···

On Thu, Jul 26, 2018 at 6:50 PM, Angelo Fausti [email protected] wrote:

On Fri, Jul 20, 2018 at 5:03 PM, Angelo Fausti [email protected] wrote:

On Fri, Jul 20, 2018 at 2:51 PM, Angelo Fausti [email protected] wrote:

Hi,

I agrees that appears to be the same bug. I don't have any workarounds to offer you at the moment, except perhaps to try other older versions of Bokeh which might not have the bug.

Thanks,

Bryan

···

On Jul 28, 2018, at 21:39, Angelo Fausti <[email protected]> wrote:

Update: I think what I am seeing

document.js:412 Uncaught Error: reference {"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not in Document?)

is related to this issue

Error message on the browser console when using CustomJS with args in serve mode · Issue #7970 · bokeh/bokeh · GitHub

and similar errors are seen in the js_events.py example at https://github.com/bokeh/bokeh/blob/master/examples/howto/

Anyways, the code to reproduce it is:

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.models.widgets import Div
from bokeh.layouts import widgetbox, column

title = Div(text="")

plot = figure()

callback = CustomJS(args={'title': title}, code="""title.text='Reset event ocurred.'""")

plot.js_on_event('reset', callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

Run as

$ bokeh serve --log-level debug app.py

with bokeh 0.13.0

thanks,

Angelo Fausti

On Thu, Jul 26, 2018 at 6:50 PM, Angelo Fausti <[email protected]> wrote:
>
> So, the error I had before
>
> document.js:412 Uncaught Error: reference {"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not in Document?)
>
> happens at
>
> plot.js_on_event('reset', callback)
>
> as the message suggests I tried to configure the callback after adding the Div widget to the bokeh document, like this:
>
> from bokeh.io import curdoc
> from bokeh.plotting import figure
> from bokeh.models.callbacks import CustomJS
> from bokeh.models.widgets import Div
> from bokeh.layouts import widgetbox, column
>
> title = Div(text="")
>
> plot = figure()
>
> callback = CustomJS(args={'title': title}, code="""title.text='Reset event ocurred.'""")
>
> layout = column(widgetbox(title), plot)
>
> curdoc().add_root(layout)
>
> plot.js_on_event('reset', callback) # moved this line to here
>
>
> But then I get another error in the JS console:
>
> connection.js:178 [bokeh] Failed to repull session Error: reference {"id":"338aa405-4f2e-4292-b044-a63141bd2c38","type":"CustomJS"} isn't known (not in Document?)
>
> and this time the app does not show up in the browser.
>
> In both cases I'm running the server with --log-level debug but there's nothing in the bokeh server logs.
>
> $ bokeh serve --log-level debug app.py
>
> I would appreciate any help to understand what is going on.
>
> thanks,
>
> Angelo Fausti
>
>
> On Fri, Jul 20, 2018 at 5:03 PM, Angelo Fausti <[email protected]> wrote:
>>
>>
>> So, the following code works, I managed to update the Div text property when the plot reset tool is used. But I am getting this error in the JS console:
>>
>> document.js:412 Uncaught Error: reference {"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not in Document?)
>>
>> why is that?
>>
>>
>> from bokeh.io import curdoc
>> from bokeh.plotting import figure
>> from bokeh.models.callbacks import CustomJS
>> from bokeh.models.widgets import Div
>> from bokeh.layouts import widgetbox, column
>>
>> title = Div(text="")
>>
>> plot = figure()
>>
>> callback = CustomJS(args={'title': title}, code="""title.text='Reset event ocurred.'""")
>>
>> plot.js_on_event('reset', callback)
>>
>> layout = column(widgetbox(title), plot)
>>
>> curdoc().add_root(layout)
>>
>> I would like to do something similar in my bokeh application that's why I am running with bokeh server.
>>
>> Bokeh version 0.13.0
>>
>> thanks,
>>
>> Angelo Fausti
>>
>>
>> On Fri, Jul 20, 2018 at 2:51 PM, Angelo Fausti <[email protected]> wrote:
>>>
>>> Hi,
>>>
>>> I have CustomJS calback attached to a datasource that I use to recompute an average whenever the selection changes.
>>>
>>> http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-model-property-events
>>>
>>> self.pcircle.data_source.on_change('selected', self.calculate_avg_temp)
>>>
>>> def calculate_avg_temp(self, attr, old, new):
>>> index = new['1d']['indices']
>>> if len(index) == 0:
>>> return
>>> index.sort()
>>> self.update_ave_temp(np.mean(np.array(self.cds.data['temperatures'])[index]))
>>>
>>>
>>> and it works fine.
>>>
>>>
>>> Then I would like to clear the selection and reset the average value.
>>>
>>> Can I use a CustomJS callback for the plot reset tool? is there an example for that? or do you recommend another method.
>>>
>>> thank you,
>>>
>>> Angelo Fausti
>>>
>>
>

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAD%3DOK5OZxsQjBV9Jo-KyGXE5cpRMu%3DyXb5mkQ%3Dj9oA63YM-nKw%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks Bryan, the bug is not critical, I mean despite the error message everything else works. I can live with that for the moment. Is there a procedure to link this thread with the github issue?

Best,

···

On Jul 29, 2018, at 1:06 PM, Bryan Van de ven <[email protected]> wrote:

Hi,

I agrees that appears to be the same bug. I don't have any workarounds to offer you at the moment, except perhaps to try other older versions of Bokeh which might not have the bug.

Thanks,

Bryan

On Jul 28, 2018, at 21:39, Angelo Fausti <[email protected]> wrote:

Update: I think what I am seeing

document.js:412 Uncaught Error: reference {"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not in Document?)

is related to this issue

Error message on the browser console when using CustomJS with args in serve mode · Issue #7970 · bokeh/bokeh · GitHub

and similar errors are seen in the js_events.py example at https://github.com/bokeh/bokeh/blob/master/examples/howto/

Anyways, the code to reproduce it is:

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.models.widgets import Div
from bokeh.layouts import widgetbox, column

title = Div(text="")

plot = figure()

callback = CustomJS(args={'title': title}, code="""title.text='Reset event ocurred.'""")

plot.js_on_event('reset', callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

Run as

$ bokeh serve --log-level debug app.py

with bokeh 0.13.0

thanks,

Angelo Fausti

On Thu, Jul 26, 2018 at 6:50 PM, Angelo Fausti <[email protected]> wrote:

So, the error I had before

document.js:412 Uncaught Error: reference {"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not in Document?)

happens at

plot.js_on_event('reset', callback)

as the message suggests I tried to configure the callback after adding the Div widget to the bokeh document, like this:

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.models.widgets import Div
from bokeh.layouts import widgetbox, column

title = Div(text="")

plot = figure()

callback = CustomJS(args={'title': title}, code="""title.text='Reset event ocurred.'""")

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

plot.js_on_event('reset', callback) # moved this line to here

But then I get another error in the JS console:

connection.js:178 [bokeh] Failed to repull session Error: reference {"id":"338aa405-4f2e-4292-b044-a63141bd2c38","type":"CustomJS"} isn't known (not in Document?)

and this time the app does not show up in the browser.

In both cases I'm running the server with --log-level debug but there's nothing in the bokeh server logs.

$ bokeh serve --log-level debug app.py

I would appreciate any help to understand what is going on.

thanks,

Angelo Fausti

On Fri, Jul 20, 2018 at 5:03 PM, Angelo Fausti <[email protected]> wrote:

So, the following code works, I managed to update the Div text property when the plot reset tool is used. But I am getting this error in the JS console:

document.js:412 Uncaught Error: reference {"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not in Document?)

why is that?

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.models.widgets import Div
from bokeh.layouts import widgetbox, column

title = Div(text="")

plot = figure()

callback = CustomJS(args={'title': title}, code="""title.text='Reset event ocurred.'""")

plot.js_on_event('reset', callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

I would like to do something similar in my bokeh application that's why I am running with bokeh server.

Bokeh version 0.13.0

thanks,

Angelo Fausti

On Fri, Jul 20, 2018 at 2:51 PM, Angelo Fausti <[email protected]> wrote:

Hi,

I have CustomJS calback attached to a datasource that I use to recompute an average whenever the selection changes.

http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-model-property-events

self.pcircle.data_source.on_change('selected', self.calculate_avg_temp)

def calculate_avg_temp(self, attr, old, new):
   index = new['1d']['indices']
   if len(index) == 0:
       return
   index.sort()
   self.update_ave_temp(np.mean(np.array(self.cds.data['temperatures'])[index]))

and it works fine.

Then I would like to clear the selection and reset the average value.

Can I use a CustomJS callback for the plot reset tool? is there an example for that? or do you recommend another method.

thank you,

Angelo Fausti

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAD%3DOK5OZxsQjBV9Jo-KyGXE5cpRMu%3DyXb5mkQ%3Dj9oA63YM-nKw%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A8335B6B-9E47-471C-A703-C298919206A6%40anaconda.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

I’m seeing the same bug, however it totally broke all my callbacks and they don’t work anymore. Furthermore the fix suggested by matpap here: Error message on the browser console when using CustomJS with args in serve mode · Issue #7970 · bokeh/bokeh · GitHub to simply remove the args parameter in the CustomJS callback is totally useless if you’re passing various other Bokeh objects (such as other plot objects to be changed) and dont just want to chanhe properties of the cb_obj.

I upgraded from 0.12.15 because of the bug where the DataTable cannot be edited because of a comment Bryan made saying many bugs have been fixed for the tables since May.

Honestly this should be high priority on the bugfix issues since CustomJS callbacks are one of the maain features which makes Bokeh (imo) interesting and usable for any type of user interaction.

···

On Sunday, July 29, 2018 at 11:21:22 PM UTC+2, Angelo Fausti Neto wrote:

Thanks Bryan, the bug is not critical, I mean despite the error message everything else works. I can live with that for the moment. Is there a procedure to link this thread with the github issue?

Best,

On Jul 29, 2018, at 1:06 PM, Bryan Van de ven [email protected] wrote:

Hi,

I agrees that appears to be the same bug. I don’t have any workarounds to offer you at the moment, except perhaps to try other older versions of Bokeh which might not have the bug.

Thanks,

Bryan

On Jul 28, 2018, at 21:39, Angelo Fausti [email protected] wrote:

Update: I think what I am seeing

document.js:412 Uncaught Error: reference {“id”:“58779667-2eb0-40c1-ab52-d3b1928cd2a0”,“type”:“Div”} isn’t known (not in Document?)

is related to this issue

https://github.com/bokeh/bokeh/issues/7970

and similar errors are seen in the js_events.py example at https://github.com/bokeh/bokeh/blob/master/examples/howto/

Anyways, the code to reproduce it is:

from bokeh.io import curdoc

from bokeh.plotting import figure

from bokeh.models.callbacks import CustomJS

from bokeh.models.widgets import Div

from bokeh.layouts import widgetbox, column

title = Div(text=“”)

plot = figure()

callback = CustomJS(args={‘title’: title}, code=“”“title.text=‘Reset event ocurred.’”“”)

plot.js_on_event(‘reset’, callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

Run as

$ bokeh serve --log-level debug app.py

with bokeh 0.13.0

thanks,

Angelo Fausti

On Thu, Jul 26, 2018 at 6:50 PM, Angelo Fausti [email protected] wrote:

So, the error I had before

document.js:412 Uncaught Error: reference {“id”:“58779667-2eb0-40c1-ab52-d3b1928cd2a0”,“type”:“Div”} isn’t known (not in Document?)

happens at

plot.js_on_event(‘reset’, callback)

as the message suggests I tried to configure the callback after adding the Div widget to the bokeh document, like this:

from bokeh.io import curdoc

from bokeh.plotting import figure

from bokeh.models.callbacks import CustomJS

from bokeh.models.widgets import Div

from bokeh.layouts import widgetbox, column

title = Div(text=“”)

plot = figure()

callback = CustomJS(args={‘title’: title}, code=“”“title.text=‘Reset event ocurred.’”“”)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

plot.js_on_event(‘reset’, callback) # moved this line to here

But then I get another error in the JS console:

connection.js:178 [bokeh] Failed to repull session Error: reference {“id”:“338aa405-4f2e-4292-b044-a63141bd2c38”,“type”:“CustomJS”} isn’t known (not in Document?)

and this time the app does not show up in the browser.

In both cases I’m running the server with --log-level debug but there’s nothing in the bokeh server logs.

$ bokeh serve --log-level debug app.py

I would appreciate any help to understand what is going on.

thanks,

Angelo Fausti

On Fri, Jul 20, 2018 at 5:03 PM, Angelo Fausti [email protected] wrote:

So, the following code works, I managed to update the Div text property when the plot reset tool is used. But I am getting this error in the JS console:

document.js:412 Uncaught Error: reference {“id”:“58779667-2eb0-40c1-ab52-d3b1928cd2a0”,“type”:“Div”} isn’t known (not in Document?)

why is that?

from bokeh.io import curdoc

from bokeh.plotting import figure

from bokeh.models.callbacks import CustomJS

from bokeh.models.widgets import Div

from bokeh.layouts import widgetbox, column

title = Div(text=“”)

plot = figure()

callback = CustomJS(args={‘title’: title}, code=“”“title.text=‘Reset event ocurred.’”“”)

plot.js_on_event(‘reset’, callback)

layout = column(widgetbox(title), plot)

curdoc().add_root(layout)

I would like to do something similar in my bokeh application that’s why I am running with bokeh server.

Bokeh version 0.13.0

thanks,

Angelo Fausti

On Fri, Jul 20, 2018 at 2:51 PM, Angelo Fausti [email protected] wrote:

Hi,

I have CustomJS calback attached to a datasource that I use to recompute an average whenever the selection changes.

http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-model-property-events

self.pcircle.data_source.on_change(‘selected’, self.calculate_avg_temp)

def calculate_avg_temp(self, attr, old, new):

index = new[‘1d’][‘indices’]

if len(index) == 0:

   return

index.sort()

self.update_ave_temp(np.mean(np.array(self.cds.data[‘temperatures’])[index]))

and it works fine.

Then I would like to clear the selection and reset the average value.

Can I use a CustomJS callback for the plot reset tool? is there an example for that? or do you recommend another method.

thank you,

Angelo Fausti


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAD%3DOK5OZxsQjBV9Jo-KyGXE5cpRMu%3DyXb5mkQ%3Dj9oA63YM-nKw%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A8335B6B-9E47-471C-A703-C298919206A6%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Copied response from GH:

As far as I understand it, the error message is merely a nuisance, but does not actually prevent any callbacks from functioning. In particular, the code at the top of this issue prints a console error, but otherwise function. Do you have a counter-example to this that you can provide? Are you sure that your problem is not actually different one and that you aren't mis-ascribing the root cause?

Please continue discussion on GH as having the same conversation scattered over two places is a burden on maintainers.

Thanks,

Bryan

···

On Aug 1, 2018, at 06:05, 'omearac' via Bokeh Discussion - Public <[email protected]> wrote:

I'm seeing the same bug, however it totally broke all my callbacks and they don't work anymore. Furthermore the fix suggested by matpap here: Error message on the browser console when using CustomJS with args in serve mode · Issue #7970 · bokeh/bokeh · GitHub to simply remove the args parameter in the CustomJS callback is totally useless if you're passing various other Bokeh objects (such as other plot objects to be changed) and dont just want to chanhe properties of the cb_obj.

I upgraded from 0.12.15 because of the bug where the DataTable cannot be edited because of a comment Bryan made saying many bugs have been fixed for the tables since May.

Honestly this should be high priority on the bugfix issues since CustomJS callbacks are one of the maain features which makes Bokeh (imo) interesting and usable for any type of user interaction.

On Sunday, July 29, 2018 at 11:21:22 PM UTC+2, Angelo Fausti Neto wrote:
Thanks Bryan, the bug is not critical, I mean despite the error message everything else works. I can live with that for the moment. Is there a procedure to link this thread with the github issue?

Best,

> On Jul 29, 2018, at 1:06 PM, Bryan Van de ven <[email protected]> wrote:
>
> Hi,
>
> I agrees that appears to be the same bug. I don't have any workarounds to offer you at the moment, except perhaps to try other older versions of Bokeh which might not have the bug.
>
> Thanks,
>
> Bryan
>
>> On Jul 28, 2018, at 21:39, Angelo Fausti <[email protected]> wrote:
>>
>>
>> Update: I think what I am seeing
>>
>> document.js:412 Uncaught Error: reference {"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not in Document?)
>>
>> is related to this issue
>>
>> Error message on the browser console when using CustomJS with args in serve mode · Issue #7970 · bokeh/bokeh · GitHub
>>
>> and similar errors are seen in the js_events.py example at https://github.com/bokeh/bokeh/blob/master/examples/howto/
>>
>> Anyways, the code to reproduce it is:
>>
>> from bokeh.io import curdoc
>> from bokeh.plotting import figure
>> from bokeh.models.callbacks import CustomJS
>> from bokeh.models.widgets import Div
>> from bokeh.layouts import widgetbox, column
>>
>> title = Div(text="")
>>
>> plot = figure()
>>
>> callback = CustomJS(args={'title': title}, code="""title.text='Reset event ocurred.'""")
>>
>> plot.js_on_event('reset', callback)
>>
>> layout = column(widgetbox(title), plot)
>>
>> curdoc().add_root(layout)
>>
>> Run as
>>
>> bokeh serve \-\-log\-level debug app\.py &gt;&gt; &gt;&gt; with bokeh 0\.13\.0 &gt;&gt; &gt;&gt; thanks, &gt;&gt; &gt;&gt; Angelo Fausti &gt;&gt; &gt;&gt; &gt;&gt;&gt; On Thu, Jul 26, 2018 at 6:50 PM, Angelo Fausti &lt;angelo\.\.\.@gmail\.com&gt; wrote: &gt;&gt;&gt; &gt;&gt;&gt; So, the error I had before &gt;&gt;&gt; &gt;&gt;&gt; document\.js:412 Uncaught Error: reference \{&quot;id&quot;:&quot;58779667\-2eb0\-40c1\-ab52\-d3b1928cd2a0&quot;,&quot;type&quot;:&quot;Div&quot;\} isn&#39;t known \(not in Document?\) &gt;&gt;&gt; &gt;&gt;&gt; happens at &gt;&gt;&gt; &gt;&gt;&gt; plot\.js\_on\_event\(&#39;reset&#39;, callback\) &gt;&gt;&gt; &gt;&gt;&gt; as the message suggests I tried to configure the callback after adding the Div widget to the bokeh document, like this: &gt;&gt;&gt; &gt;&gt;&gt; from bokeh\.io import curdoc &gt;&gt;&gt; from bokeh\.plotting import figure &gt;&gt;&gt; from bokeh\.models\.callbacks import CustomJS &gt;&gt;&gt; from bokeh\.models\.widgets import Div &gt;&gt;&gt; from bokeh\.layouts import widgetbox, column &gt;&gt;&gt; &gt;&gt;&gt; title = Div\(text=&quot;&quot;\) &gt;&gt;&gt; &gt;&gt;&gt; plot = figure\(\) &gt;&gt;&gt; &gt;&gt;&gt; callback = CustomJS\(args=\{&#39;title&#39;: title\}, code=&quot;&quot;&quot;title\.text=&#39;Reset event ocurred\.&#39;&quot;&quot;&quot;\) &gt;&gt;&gt; &gt;&gt;&gt; layout = column\(widgetbox\(title\), plot\) &gt;&gt;&gt; &gt;&gt;&gt; curdoc\(\)\.add\_root\(layout\) &gt;&gt;&gt; &gt;&gt;&gt; plot\.js\_on\_event\(&#39;reset&#39;, callback\) \# moved this line to here &gt;&gt;&gt; &gt;&gt;&gt; &gt;&gt;&gt; But then I get another error in the JS console: &gt;&gt;&gt; &gt;&gt;&gt; connection\.js:178 \[bokeh\] Failed to repull session Error: reference \{&quot;id&quot;:&quot;338aa405\-4f2e\-4292\-b044\-a63141bd2c38&quot;,&quot;type&quot;:&quot;CustomJS&quot;\} isn&#39;t known \(not in Document?\) &gt;&gt;&gt; &gt;&gt;&gt; and this time the app does not show up in the browser\. &gt;&gt;&gt; &gt;&gt;&gt; In both cases I&#39;m running the server with \-\-log\-level debug but there&#39;s nothing in the bokeh server logs\. &gt;&gt;&gt; &gt;&gt;&gt; bokeh serve --log-level debug app.py
>>>
>>> I would appreciate any help to understand what is going on.
>>>
>>> thanks,
>>>
>>> Angelo Fausti
>>>
>>>
>>>> On Fri, Jul 20, 2018 at 5:03 PM, Angelo Fausti <[email protected]> wrote:
>>>>
>>>>
>>>> So, the following code works, I managed to update the Div text property when the plot reset tool is used. But I am getting this error in the JS console:
>>>>
>>>> document.js:412 Uncaught Error: reference {"id":"58779667-2eb0-40c1-ab52-d3b1928cd2a0","type":"Div"} isn't known (not in Document?)
>>>>
>>>> why is that?
>>>>
>>>>
>>>> from bokeh.io import curdoc
>>>> from bokeh.plotting import figure
>>>> from bokeh.models.callbacks import CustomJS
>>>> from bokeh.models.widgets import Div
>>>> from bokeh.layouts import widgetbox, column
>>>>
>>>> title = Div(text="")
>>>>
>>>> plot = figure()
>>>>
>>>> callback = CustomJS(args={'title': title}, code="""title.text='Reset event ocurred.'""")
>>>>
>>>> plot.js_on_event('reset', callback)
>>>>
>>>> layout = column(widgetbox(title), plot)
>>>>
>>>> curdoc().add_root(layout)
>>>>
>>>> I would like to do something similar in my bokeh application that's why I am running with bokeh server.
>>>>
>>>> Bokeh version 0.13.0
>>>>
>>>> thanks,
>>>>
>>>> Angelo Fausti
>>>>
>>>>
>>>>> On Fri, Jul 20, 2018 at 2:51 PM, Angelo Fausti <[email protected]> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I have CustomJS calback attached to a datasource that I use to recompute an average whenever the selection changes.
>>>>>
>>>>> http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-model-property-events
>>>>>
>>>>> self.pcircle.data_source.on_change('selected', self.calculate_avg_temp)
>>>>>
>>>>> def calculate_avg_temp(self, attr, old, new):
>>>>> index = new['1d']['indices']
>>>>> if len(index) == 0:
>>>>> return
>>>>> index.sort()
>>>>> self.update_ave_temp(np.mean(np.array(self.cds.data['temperatures'])[index]))
>>>>>
>>>>>
>>>>> and it works fine.
>>>>>
>>>>>
>>>>> Then I would like to clear the selection and reset the average value.
>>>>>
>>>>> Can I use a CustomJS callback for the plot reset tool? is there an example for that? or do you recommend another method.
>>>>>
>>>>> thank you,
>>>>>
>>>>> Angelo Fausti
>>>>>
>>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
>> To post to this group, send email to bo...@continuum.io.
>> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAD%3DOK5OZxsQjBV9Jo-KyGXE5cpRMu%3DyXb5mkQ%3Dj9oA63YM-nKw%40mail.gmail.com\.
>> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A8335B6B-9E47-471C-A703-C298919206A6%40anaconda.com\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e7e2197c-f834-4e58-9002-536b5c443539%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.