Hello,
I have the following code with this table but I am not able to make that only the selected rows of the selected points in the chart appear, that is to say, when I select points, the blank rows of unselected points do not appear.
Would it be possible that these rows do not appear?
Something aesthetic but I would like to know if it is possible to have the values that appear in the table centered in some way.
Thanks in advance.
import pandas as pd
import numpy as np
from bokeh.models import (ColumnDataSource, DataTable, TableColumn
)
from bokeh.plotting import figure, curdoc, show
from bokeh.layouts import row
x = np.random.sample(10)
y = np.random.sample(10)
z = np.random.sample(10)
l = ['P'+str(n) for n in range(len(z))]
c = ['skyblue']*len(x)
cl= ['c1']*4 + ['c2']*3 + ['c3']*3
dataf = pd.DataFrame({'Var1': x, 'Var2': y, 'Var3': z, 'Label': l, 'color': c, 'class': cl} )
source = ColumnDataSource(data=dict(x=dataf['Var1'],
y=dataf['Var2'],
z=dataf['Var3'],
l=dataf['Label'],
c=dataf['color']
))
p1 = figure(plot_width=800, plot_height=700,
tools="tap,pan,lasso_select,wheel_zoom,save,reset",
toolbar_location="above",
)
p1.circle(x="x", y="y",color='c' ,fill_alpha=0.8 ,source=source, size=10,
selection_line_color="darkblue")
columns = [TableColumn(field=n,title=n) for n in ['Var1','Var2','Var3','Label']]
table = DataTable(source=source,columns=columns, width=800, height=300)
def update_table(data):
table.source = ColumnDataSource(data)
def selection_change(attrname, old, new):
data = dataf.copy()
selected = source.selected.indices
if selected:
data = data.iloc[selected, :]
update_table(data)
source.selected.on_change('indices', selection_change)
display = row(p1,table)
curdoc().add_root(display)