question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Shared ColumnDataSource issues in JS callback (Uncaught TypeError: Cannot read property 'connect' of undefined)

See original GitHub issue

ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

Python version      :  3.7.2 (default, Mar 15 2019, 01:06:31) 
IPython version     :  (not installed)
Tornado version     :  6.0.3
Bokeh version       :  1.3.0
BokehJS static path :  /usr/local/lib/python3.7/site-packages/bokeh/server/static
node.js version     :  v10.15.1
npm version         :  6.10.0

OS: Mac OS X Mojave 10.14.6 Browser: Google Chrome Version 76.0.3809.100 (Official Build) (64-bit)

Description of expected behavior and the observed behavior Expected behavior: page should open and a plot containing line and circles should be shown

Observed behavior: a new page opens but no plot is shown. The following JS error is given in JS console in the browser:

Uncaught TypeError: Cannot read property 'connect' of undefined
    at e.t.connect (bokeh-1.3.0.min.js:31)
    at n (bokeh-1.3.0.min.js:31)
    at e.connect_signals (bokeh-1.3.0.min.js:31)
    at e.finalize (bokeh-1.3.0.min.js:31)
    at bokeh-1.3.0.min.js:31
    at i (bokeh-1.3.0.min.js:31)
    at i (bokeh-1.3.0.min.js:31)
    at i (bokeh-1.3.0.min.js:31)
    at i (bokeh-1.3.0.min.js:31)
    at i (bokeh-1.3.0.min.js:31)

Complete, minimal, self-contained example code that reproduces the issue

main.py

from bokeh.plotting import show, figure
from bokeh.models import ColumnDataSource, CustomJS

p = figure()

source = ColumnDataSource(dict(x = [1, 2], y = [2, 1]))
line = p.line('x', 'y', source = source)
circle = p.circle('x', 'y', source = source)

glyphs = [line, circle]
                       
source.selected.js_on_change('indices', 
                             CustomJS(args = {'glyphs': glyphs},  
                                      code = 'console.log("OK")'))                                                            
show(p)

Additional Info

When I replace the code with:

from bokeh.plotting import show, figure
from bokeh.models import ColumnDataSource, CustomJS

p = figure()

line = p.line(x = [1, 2], y = [2, 1])
circle = p.circle(x = [1, 2], y = [2, 1])

glyphs = [line, circle]
                       
glyphs[0].data_source.selected.js_on_change('indices', 
                                            CustomJS(args = {'glyphs': glyphs},  
                                                     code = 'console.log("OK")'))                                                            
glyphs[1].data_source.selected.js_on_change('indices', 
                                            CustomJS(args = {'glyphs': glyphs},  
                                                     code = 'console.log("OK")'))     
show(p)

then everything works fine. Another option is to create a separate source for each glyph (which is not the best solution):

from bokeh.plotting import show, figure
from bokeh.models import ColumnDataSource, CustomJS

p = figure()

source_line = ColumnDataSource(dict(x = [1, 2], y = [2, 1]))
source_circle = ColumnDataSource(dict(x = [1, 2], y = [2, 1]))
line = p.line('x', 'y', source = source_line)
circle = p.circle('x', 'y', source = source_circle)

glyphs = [line, circle]
                       
source_line.selected.js_on_change('indices', 
                                  CustomJS(args = {'glyphs': glyphs},  
                                           code = 'console.log("OK")'))  
source_circle.selected.js_on_change('indices', 
                                  CustomJS(args = {'glyphs': glyphs},  
                                           code = 'console.log("OK")'))                                                          
show(p)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mattpapcommented, May 6, 2020

Do you have any thoughts on the possibility of such cycles?

Not yet. If you can, please submit a PR with your original solution. We can always improve this later.

0reactions
p-himikcommented, May 6, 2020

This just popped up again at https://discourse.bokeh.org/t/reset-zoom-after-data-source-update-from-bokeh-server/5340/11

I now realize that circular references are definitely possible, and are completely justified. In the example above, ColumnDataSource has CustomJS, which has GlyphRenderer, which has the data source. @mattpap Do you have any thoughts on the possibility of such cycles?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bokeh RangeSlider callback issue, source.change.emit ...
However, when I try to run the code, it gives me the error "Cannot read property 'emit' of undefined" when I check the...
Read more >
Errors | Node.js v19.3.0 Documentation
When the operation either completes or an error is raised, the callback function is called with the Error object (if any) passed as...
Read more >
Understanding change.emit() with filters/sources/glyphs
Two buttons do two different callbacks: one will change the ys ... VM2042:8 Uncaught TypeError: Cannot read property 'emit' of undefined at ...
Read more >
How to convert between callbacks and Promises in Javascript
How to use the promisify and callbackify functions, and when they are not enough ... Error: Cannot read property 'connection' of undefined.
Read more >
A Comprehensive Guide To Error Handling In Node.js
If you fail to catch it, it becomes an uncaught exception, which may cause your application to crash! How to deliver errors. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found