Hi , all.
Now I am making item selection in FastListTemplate. at this time , I want to reduce interact times. Here is my sample screen shot.
[ Screen Shot ]
[My problem]
I selected one-item(weight) in Graph tab. And this value transfer to List tab and select in table. It works fine. But my code execute many times selection table code.
Here is proof.
above photo , table list selection code execute 3times ( 8,9,10 times ) although my intend execute one time.
And my simple code is below
[ My simple code ]
from bokeh.sampledata.autompg import autompg
import pandas as pd;
import panel as pn
import param
from panel.template import DarkTheme,DefaultTheme
pn.extension()
import hvplot.pandas
columns = list(autompg.columns[:-2])
x = pn.widgets.Select(value='mpg', options=columns, name='x')
y = pn.widgets.Select(value='hp', options=columns, name='y')
color = pn.widgets.ColorPicker(name='Color', value='#AA0505')
# ----------------------------------------------------------------------
# Selcetion Table
# ----------------------------------------------------------------------
class ReactiveTable(param.Parameterized):
table = param.DataFrame(default=pd.DataFrame(columns))
v1 = param.Number()
def __init__(self, **params):
super().__init__(**params)
self.table_widget = pn.Param(self.param.table)[0]
@param.depends('table_widget.selection')
def update_params_with_selected_row_values(self):
param_test = self.table_widget.selection
if len(param_test) != 0 :
self.v1 += 1
print ('20211118 Table list selection: ', param_test,columns[param_test[0]], 'exe ' , self.v1 , 'times')
x.value = columns[param_test[0]]
return self.table_widget.selection
rt = ReactiveTable()
# ----------------------------------------------------------------------
# index search
# ----------------------------------------------------------------------
def search_index(lst, value):
return [i for i, x in enumerate(lst) if x == value]
# ----------------------------------------------------------------------
# Graph tab
# ----------------------------------------------------------------------
@pn.depends(x, y, color)
def autompg_plot(xval, yval, colorval ):
rt.table_widget.selection =search_index(columns,xval)
print ('20211118 Graph selection: ',rt.table_widget.selection)
return autompg.hvplot.scatter(xval, yval, c=colorval)
# ----------------------------------------------------------------------
# Table tab
# ----------------------------------------------------------------------
@pn.depends( x, y, color)
def test_list( x, y, color):
ret_view = pn.Column(pn.Row(rt.param.v1),rt.table_widget, rt.update_params_with_selected_row_values)
return ret_view
# ----------------------------------------------------------------------
# main screen
# ----------------------------------------------------------------------
select_tab = 0
def main_tabs(sel_tab = select_tab):
ret_main_tabs = pn.Tabs(
('Graph', pn.Row(pn.Column('## MPG Explorer', x, y, color), autompg_plot)),
('List', test_list)
)
ret_main_tabs.active = sel_tab
return ret_main_tabs
# ----------------------------------------------------------------------
# make template and run server
# ----------------------------------------------------------------------
template = pn.template.FastListTemplate(
title='Panel Sample',
site='Panel',
main=main_tabs(select_tab),
theme = DarkTheme ,
theme_toggle = True ,
)
template.servable();
pn.serve(template)
Above is a simple code. so execution delay is no problem . But my real program is big. so I can’t ignore this execution delay. so someone help me teaching to reduce interact time?