Hi,
Bokeh is a great package and so I first want to thank the developers for these tools and I am using bokeh 0.12.7.
I am looking to create a plot from data I download by a custom query to a api in django app.
I got the Select widget for user input and Button click to work using CustomJS. I just do not get the plot to update.
What am I missing in the following CustomJS callback?
source = ColumnDataSource(data=dict(x=[2],y=[2])
callback_click_crossfilter = CustomJS(args=dict(source=source),code="""
xhr = new XMLHttpRequest();
xhr.open(‘GET’, “https://researchdata.nist.gov/resource/x4qp-eedm.json?&dft_code=DMol3&crystal_structure=hcp”, true);
xhr.send();
xhr.onreadystatechange = processRequest;
function processRequest(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log('ok');
var response = JSON.parse(xhr.responseText);
getData(response);
console.log('finished');
}
}
function getData(main) {
data = source.data;
var x = data['x'];
var y = data['y'];
x = [];
y = [];
for (var i = 0; i < main.length; i++ ) {
x.push(main[i].k_point_density_per_atom);
y.push(main[i].precision_of_dft_energy_mev_per_atom);
}
console.log(x);
}
source.change.emit();
“”")
``
And the python functions:
plot = figure(plot_width=400, plot_height=400,x_axis_type=‘log’,y_axis_type=‘log’,
y_range = (1e-6,1), x_range = (10, 1e5),tools=‘box_zoom,hover,pan,reset’)
plot.circle(‘x’, ‘y’, source=source)
button = Button(label=‘CrossFilter’,button_type=‘success’)
button.js_on_event(events.ButtonClick,callback_click_crossfilter)
layout = column(button,plot)
output_file(“test.html”)
show(layout)
``
For the last console.log(x) I get the desired array that should go to source.data[‘x’] with the javascript I used. I intend to put this into a django app eventually. Please let me know if this is feasible for a python2.7 compatible bokeh.
Thanks
Joshua