How to make a DataTable with the variable coming from selected data?

Hello,

I want to make a data table according to variables coming from the selected area. When I run the code below it gives me the variables in the console (shown in Fig) but I want to make a constant data table next to graphs that updates it self according to the selected data.

I try to make a table with adding the code below to the function but it opened a new tab for each time when function called. how can I solve this problem.

    columns = [
    TableColumn(field= 'test1' , title='Minimum Selection of %s'%(legend_label)),
    TableColumn(field= 'test1' , title='Minimum Selection of %s'%(legend_label))
    ]
    
    columns = [TableColumn(field ='%s'%(math.min(sel_src1[])) ,title = 'Minimum Selection of %s'%(legend_label)),
                
               TableColumn(field = math.max(sel_src1[])  ,title = 'Minimum Selection of %s'%(legend_label))
                ]
         
     myTable = DataTable(source=s1, columns=columns) 
     
     show(myTable)



import pandas as pd
from bokeh.plotting import figure,show,gridplot,output_file
from bokeh.models import ColumnDataSource,CustomJS, HoverTool, Legend, ColumnDataSource, TableColumn, DataTable
import math, random


def Plotter(value1,p,color,legend_label):
    
    
    dataset1       = pd.DataFrame(data={'time1':range(len(value1)),'data1':value1})
    s1             = ColumnDataSource(data=dataset1) 
    
    
    
    line_rend1 = p.line('time1', 'data1', color=color,legend_label=legend_label, line_width=1,source=s1)
    line_rend1.selection_glyph = line_rend1.glyph
    line_rend1.nonselection_glyph = line_rend1.glyph
    
    scatter_rend1 = p.scatter('time1','data1',fill_alpha=0,source=s1,line_alpha=0)
    scatter_rend1.selection_glyph = scatter_rend1.glyph
    scatter_rend1.nonselection_glyph = scatter_rend1.glyph
    
    p.add_tools(HoverTool(renderers = [line_rend1],
        tooltips = [
            
            ( 'index', '$index'),
            ( 'Value', '@data1'),
        ],
        
    formatters={
            'Index'      : 'numeral',         # use 'datetime' formatter for 'date' field
            'Value'      : 'numeral',         # use default 'numeral' formatter for other fields
    },
    
    mode='vline'
    ))
    
    sel_src1 = ColumnDataSource(data={'time1':[],'data1':[]})
    sel_line_render1 = p.line('time1','data1',legend_label='Selected',line_color='orange',source=sel_src1)
   
    
    cb1=CustomJS(args=dict(s1=s1,sel_src=sel_src1)
                ,code='''
                var sel_inds = s1.selected.indices
                var sel_time = []
                var sel_data = []
                for (var i=0;i<s1.selected.indices.length;i++){
                        sel_time.push(s1.data['time1'][sel_inds[i]])
                        sel_data.push(s1.data['data1'][sel_inds[i]])}
                console.log('Min Selection of %s:')
                console.log(Math.min(...sel_data))
                console.log('Max Selection of %s:')
                console.log(Math.max(...sel_data))
                sel_src.data['time1'] = sel_time
                sel_src.data['data1'] = sel_data
                sel_src.change.emit()
                '''%(legend_label,legend_label))
   
    s1.selected.js_on_change('indices',cb1)  
    





value1 = random.sample(range(0, 1000), 500)
value2 = random.sample(range(0, 1000), 500)
value3 = random.sample(range(0, 1000), 500)
value4 = random.sample(range(0, 1000), 500)
value5 = random.sample(range(0, 1000), 500)

    
TOOLS          ="pan,wheel_zoom,reset,poly_select,xbox_select,lasso_select" 

p11             = figure(title = 'test1' ,x_axis_label = 'time'
                  , y_axis_label='data',plot_width=1000, plot_height=300,tools=TOOLS)

p12             = figure(title = 'test1' ,x_axis_label = 'time'
                  , y_axis_label='data',plot_width=1000, plot_height=300,tools=TOOLS)


Plotter(value1,p11,'purple','Test1')

Plotter(value2,p11,'red','Test2')

Plotter(value3,p11,'green','Test3')

Plotter(value4,p12,'black','Test4')

Plotter(value5,p12,'magenta','Test5')

grid1 = gridplot([[p11],[p12]])

show(grid1)





This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.