
I want to use source in CustomJS but
source.data = mydict takes 12 secs for table 5000x4000 to create. Is there any way to reduce this time?
To reduce this time I replaced source with dict in CustomJS but it was not updated.
Below is the simple example. I clicked Run button to update sources and then clicked Save button to see if the sources were updated in browser JS. ColumnDataSource was updated but dict source was not updated.
How to get “dict” source updated in CustomJS?
Example:
from bokeh.models import ColumnDataSource
from bokeh.io import curdoc
from bokeh.models.widgets import Button
from bokeh.models.callbacks import CustomJS
from bokeh.layouts import column
source_names = ColumnDataSource(data=dict(x=[]))
output_dict = {}
def run_click():
output_dict.clear()
res_dict = {'prop1': [1,2], 'prop2': [2,5]}
source_names.data['x'] = list(res_dict.keys())
output_dict.update(res_dict)
btn_run = Button(label="Run",width=100,button_type='primary')
btn_run.on_click(run_click)
btn_save = Button(label="Save",width=100,button_type='primary')
custom_js = CustomJS(args=dict(file_source=source_names, data=output_dict), code = """
var data1 = new Object(data);
var data2 = file_source.data;
console.log(data1);
var columns = data2['x'];
const clm = String(columns[0])
console.log(clm)
console.log("Name of first key in dictionary is: " + Object.keys(data1)[0]);
console.log("Value of first key in dictionary is: " + data1[Object.keys(data1)[0]]);
"""
)
btn_save.js_on_click(custom_js)
curdoc().add_root(column(btn_run, btn_save))
