☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

CustomJS for Selections fails to run in Flask app

Community Support
russici
russici

Hello,

I have difficulties to run the following code inside a flask app. I did “copy/paste” the main part from user guide (CustomJS for Selections)

@app.route(’/select’, methods=[“POST”, “GET”])

def select():

x = [random() for x in range(500)]

y = [random() for y in range(500)]

s1 = ColumnDataSource(data=dict(x=x, y=y))

p1 = figure(plot_width=300, plot_height=300, tools=“lasso_select”, title=“Select Here”)

p1.circle(‘x’, ‘y’, source=s1, alpha=0.6)

s2 = ColumnDataSource(data=dict(x=, y=))

p2 = figure(plot_width=300, plot_height=300, x_range=(0, 1), y_range=(0, 1),

tools="", title=“Watch Here”)

p2.circle(‘x’, ‘y’, source=s2, alpha=0.6)

s1.callback = CustomJS(args=dict(s2=s2), code="""

var inds = cb_obj.selected[‘1d’].indices;

var d1 = cb_obj.data;

var d2 = s2.data;

d2[‘x’] =

d2[‘y’] =

for (i = 0; i < inds.length; i++) {

d2[‘x’].push(d1[‘x’][inds[i]])

d2[‘y’].push(d1[‘y’][inds[i]])

}

s2.change.emit();

“”")

layout = row(p1, p2)

script, div = components(layout, INLINE)

return jsonify(

script=script,

div=div,

js_resources=INLINE.render_js(),

css_resources=INLINE.render_css()

)

``

The selected points in p1 are not displayed in p2 . An error in the console says “Uncaught TypeError: Cannot read property ‘emit’ of undefined” . Any ideas what is wrong?

Thanks,

Vitali

⌁   Link to post
Bryan
Bryan

Hi,

"emit" is a very recent way of spelling things, my first guess is that your version of Bokeh is too old for this style. You can and should consult docs specific to the version you have installed, if it is not the latest, e.g.

  Welcome to Bokeh — Bokeh 0.12.5 documentation

Thanks,

Bryan

···

On Jul 26, 2017, at 17:06, russici@gmail.com wrote:

Hello,

I have difficulties to run the following code inside a flask app. I did "copy/paste" the main part from user guide (CustomJS for Selections)

@app.route('/select', methods=["POST", "GET"])
def select():
    x = [random() for x in range(500)]
    y = [random() for y in range(500)]

    s1 = ColumnDataSource(data=dict(x=x, y=y))
    p1 = figure(plot_width=300, plot_height=300, tools="lasso_select", title="Select Here")
    p1.circle('x', 'y', source=s1, alpha=0.6)
    s2 = ColumnDataSource(data=dict(x=, y=))
    p2 = figure(plot_width=300, plot_height=300, x_range=(0, 1), y_range=(0, 1),
            tools="", title="Watch Here")
    p2.circle('x', 'y', source=s2, alpha=0.6)

    s1.callback = CustomJS(args=dict(s2=s2), code="""
        var inds = cb_obj.selected['1d'].indices;
        var d1 = cb_obj.data;
        var d2 = s2.data;
        d2['x'] =
        d2['y'] =
        for (i = 0; i < inds.length; i++) {
            d2['x'].push(d1['x'][inds[i]])
            d2['y'].push(d1['y'][inds[i]])
        }
        s2.change.emit();
    """)

    layout = row(p1, p2)

    script, div = components(layout, INLINE)
    return jsonify(
        script=script,
        div=div,
        js_resources=INLINE.render_js(),
        css_resources=INLINE.render_css()
    )

The selected points in p1 are not displayed in p2 . An error in the console says "Uncaught TypeError: Cannot read property 'emit' of undefined" . Any ideas what is wrong?

Thanks,
Vitali

--
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+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2d06037b-dc2d-4b71-8ff5-01f16827f679%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post
russici
russici

Thank you so much, Bryan! As soon I changed s2.change.emit() to s2.triger(‘change’) the app started working.

···

On Wednesday, July 26, 2017 at 6:09:27 PM UTC-4, Bryan Van de ven wrote:

Hi,

“emit” is a very recent way of spelling things, my first guess is that your version of Bokeh is too old for this style. You can and should consult docs specific to the version you have installed, if it is not the latest, e.g.

    [http://bokeh.pydata.org/en/0.12.5/](http://bokeh.pydata.org/en/0.12.5/)

Thanks,

Bryan

On Jul 26, 2017, at 17:06, rus...@gmail.com wrote:

Hello,

I have difficulties to run the following code inside a flask app. I did “copy/paste” the main part from user guide (CustomJS for Selections)

@app.route(‘/select’, methods=[“POST”, “GET”])

def select():

x = [random() for x in range(500)]
y = [random() for y in range(500)]
s1 = ColumnDataSource(data=dict(x=x, y=y))
p1 = figure(plot_width=300, plot_height=300, tools="lasso_select", title="Select Here")
p1.circle('x', 'y', source=s1, alpha=0.6)
s2 = ColumnDataSource(data=dict(x=[], y=[]))
p2 = figure(plot_width=300, plot_height=300, x_range=(0, 1), y_range=(0, 1),
        tools="", title="Watch Here")
p2.circle('x', 'y', source=s2, alpha=0.6)
s1.callback = CustomJS(args=dict(s2=s2), code="""
    var inds = cb_obj.selected['1d'].indices;
    var d1 = cb_obj.data;
    var d2 = s2.data;
    d2['x'] = []
    d2['y'] = []
    for (i = 0; i < inds.length; i++) {
        d2['x'].push(d1['x'][inds[i]])
        d2['y'].push(d1['y'][inds[i]])
    }
    s2.change.emit();
""")
layout = row(p1, p2)
script, div = components(layout, INLINE)
return jsonify(
    script=script,
    div=div,
    js_resources=INLINE.render_js(),
    css_resources=INLINE.render_css()
)

The selected points in p1 are not displayed in p2 . An error in the console says “Uncaught TypeError: Cannot read property ‘emit’ of undefined” . Any ideas what is wrong?

Thanks,

Vitali

–
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/2d06037b-dc2d-4b71-8ff5-01f16827f679%40continuum.io.

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

⌁   Link to post

End of archived discussion · Replies are disabled