Hello,
I have a table that displays CDS data from the plot lasso selection tool indices. If the CDS data gets updated, is there a way to update the table without having to redo the lasso selection? The DataTable gets updated with a CustomJS callback, while the CDS gets updated with a server callback.
source = ColumnDataSource(data=dict(LDA1=dataset_LDA2D.LDA1,
LDA2=dataset_LDA2D.LDA2,
colors=dataset_LDA2D.color,
map_value=dataset_LDA2D.map_value)
lasso_source = ColumnDataSource(data=dict(LDA1=[],
LDA2=[],
colors=[],
map_value=[]))
tools_ = ['crosshair', 'zoom_in', 'zoom_out', 'save', 'reset', 'tap', 'box_zoom', 'pan', 'undo', 'redo', 'wheel_zoom']
p = figure(tools=tools_, active_drag="box_zoom", width=1800, height=2000)
p1 = p.circle('LDA1', 'LDA2', fill_color='colors',
size=7, alpha=0.5, line_alpha=0,
source=source, name='Data')
lasso_1 = LassoSelectTool(continuous=False)
p.add_tools(lasso_1)
lasso_table = DataTable(source=lasso_source, columns=[TableColumn(field='map_value', title="Map Value")], width=600, height=1500, fit_columns=True)
lasso_callback = CustomJS(args=dict(lasso_source=lasso_source, source=source, lasso_table=lasso_table), code="""
var inds = cb_obj.indices;
var s1 = source.data;
var ld = lasso_source.data;
ld['LDA1'] = [];
ld['LDA2'] = [];
ld['colors'] = [];
ld['map_value'] = [];
for (var i = 0; i < inds.length; i++) {
ld['LDA1'].push(s1['LDA1'][inds[i]]);
ld['LDA2'].push(s1['LDA2'][inds[i]]);
ld['colors'].push(s1['colors'][inds[i]]);
ld['map_value'].push(s1['map_value'][inds[i]]);
}
lasso_source.change.emit();
lasso_table.change.emit();
""")
source.selected.js_on_change('indices', lasso_callback)
heat_slider = Slider(start=1, end=4, value=1, step=1, title="Heat")
def marker_callback(attr, old, new):
path = '/myapp/data/'+directory+'/'+product_file+'.db'
con = sqlite3.connect(path)
query = 'SELECT * FROM '+product_file
product_df = pd.read_sql_query(query, con)
con.close()
if(heat_slider.value == 1):
source.data['map_value'] = product_df.product_values1.to_list()
elif(heat_slider.value == 2):
source.data['map_value'] = product_df.product_values2.to_list()
elif(heat_slider.value == 3):
source.data['map_value'] = product_df.product_values3.to_list()
elif(heat_slider.value == 4):
source.data['map_value'] = product_df.product_values4.to_list()
heat_slider.on_change('value', marker_callback)