Python의 패널-이벤트가 호출되는 순서를 설정하는 방법
패널을 사용하여 대시 보드를 만들고 컨트롤 (아래 클래스의 "임계 값")을 변경하는 방법을 알아 내려고 해당 속성을 사용할 다른 함수가 호출되기 전에 클래스의 속성을 업데이트하는 프로세스를 시작합니다. . 기본적으로 임계 값 위젯의 변경은 self.table 속성을 변경해야하며, 그러면 둘 이상의 함수가이를 참조하여 대시 보드에 대한 테이블과 플롯을 생성합니다. 어떻게해야할까요? 이것은 위젯이 선언되고 클래스가 초기화되는 클래스의 시작입니다 ....
class BinaryPerformDashComponents(param.Parameterized):
bins = param.ObjectSelector(default=10, objects=[], label='Number of Bins')
threshold = param.Number(default=0.5, step=0.01, bounds=(0, 1), allow_None=False)
def __init__(self, actual, pred, df, *args, **kwargs):
super(type(self), self).__init__(*args, **kwargs)
self.param.bins.objects =[5,10,20,50,100] # set the list of objects to select from in the widget
self.df = self.create_df(actual,pred,df)
답변
1 SandervandenOord
다음은 매개 변수 임계 값이 변경되고 부울 값이 변경되고 해당 부울이 변경되기 때문에 그 이후에 다른 업데이트가 트리거되는 예입니다.
import param
import panel as pn
pn.extension()
class BinaryPerformDashComponents(param.Parameterized):
bins = param.ObjectSelector(default=10, objects=[5,10,20,50,100], label='Number of Bins')
threshold = param.Number(default=0.5, step=0.01, bounds=(0, 1))
boolean_ = param.Boolean(True)
@param.depends('threshold', watch=True)
def _update_boolean(self):
self.boolean_ = not self.boolean_
@param.depends('boolean_', watch=True)
def _update_bins(self):
self.bins = 20
instance = BinaryPerformDashComponents()
pn.Row(instance)
다음은 동일한 메커니즘을 사용하는 몇 가지 다른 질문과 답변입니다.
버튼을 사용하여 매개 변수화 된 클래스가있는 패널에서 작업을 트리거하고 버튼 작업이 완료되면 다른 종속성이 업데이트 됨 (Holoviz)
다른 선택 위젯이 변경 될 때 드롭 다운 선택 위젯을 자동으로 업데이트하려면 어떻게합니까? (Python 패널 pyviz)