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.

Arbitraty JS at the beginning of each session

See original GitHub issue

I am trying to run JS code at the beginning of a bokeh serve session and return some values to the python side which I will use later to update the plot data. Currently I am not able to see any documentation to achieve this.

I tried the following to no avail. Is there a way to do this?

from random import random
import numpy as np

from bokeh.layouts import column, row, widgetbox, layout
from bokeh.models import Button
from bokeh.palettes import RdYlBu3
from bokeh.plotting import figure, curdoc
from bokeh.models.widgets import MultiSelect, Dropdown, Select, TextInput, PreText
from bokeh.models import ColumnDataSource, CustomJS, Slider
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn


source = ColumnDataSource(data=dict(x=[0,1,2]))
jscallback = CustomJS(args=dict(source=source), code="""

var data = source.get('data');
x = data['x']
x = x+x;
console.log(x)
source.trigger('change');

""")

slider = Slider(start=0.1, end=4, value=1, step=.1, title="power", callback=jscallback)

def printcallback():
    print(source.data['x'])

button1 = Button(label="Foo", button_type="success")
button1.on_click(printcallback)

l = row(slider, button1)
curdoc().add_root(l)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Sep 20, 2016

This capability does not yet exist.

0reactions
ImmanuelSamuelcommented, Sep 20, 2016

Ah I see yes that works however the on_change event on the source does not trigger when doing this.

In the code below moving the slider changes the source. Clicking the button shows that the source has been changed and prints out the new value. However the on change event on source is not triggered.

import numpy as np
from bokeh.layouts import column, row, widgetbox, layout
from bokeh.models import Button
from bokeh.plotting import figure, curdoc
from bokeh.models import ColumnDataSource, CustomJS, Slider


source = ColumnDataSource(data=dict(x=[0,1,2]))
def source_callback(attr, old, new):
    print(source.data['x'])
    print(new)
source.on_change('x', source_callback)


jscallback = CustomJS(args=dict(source=source), code="""
source.data = {'x': [10]}
console.log(source.data['x'])
source.trigger('change');
""")
slider = Slider(start=0.1, end=4, value=1, step=.1, title="power", callback=jscallback)


def printcallback():
    print(source.data['x'])
button1 = Button(label="Foo", button_type="success")
button1.on_click(printcallback)

l = row(slider, button1)
curdoc().add_root(l)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getter for arbitrary property of object - javascript - Stack Overflow
I know I can use Object.defineProperty to define a custom getter, I just can't wrap my head around how to access an arbitrary,...
Read more >
Queries will hang arbitrarily · Issue #148 · neo4j ... - GitHub
Occasionally, this will hang on session.run for a long period of time (~60 seconds?). After that, we get a ETIMEDOUT error.
Read more >
Tools — Acrobat-PDFL SDK: JS Developer Guide
Learn how to integrate PDF products and features in your apps with the Acrobat and PDFL APIs. Create apps that integrate with Adobe's ......
Read more >
Node.js Vulnerability Cheatsheet | ShiftLeft Blog
25 vulnerabilities to look out for in Node JS applications: Directory traversal, prototype pollution, XSSI, and more…
Read more >
Communicating with Shiny via JavaScript
Communication from JavaScript to R works by setting a reactive input. ... to run arbitrary R code in response to the value.
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