【发布时间】:2022-08-19 02:06:32
【问题描述】:
我的 dash 项目包括用户可以自定义警报的功能。这些警报出现在自定义警报列表中,并带有一个删除按钮,使用户能够从列表中删除自定义警报。
[仪表板功能截图]
此列表是使用以下代码创建的:
@callback(
Output(\'customized-list\',\'children\'),
Input(\'customized-alerts-button\',\'n_clicks\'),
State(\'customized_alerts\',\'data\'),prevent_initial_call=True)
def showCustomizedAlerts(_,customized_alerts):
return [html.H2(\'Customized alerts\', style={\"textAlign\": \"left\"}),
html.Ul([html.Li(html.Div([
html.Div([i],style={\'display\':\'inline-block\'}),
html.Div([html.Button(\'Delete alert\',id=\'delete-alert-button\'+str(customized_alerts.index(i)))],style={\'display\':\'inline-block\'})])) for i in customized_alerts])]
现在,为了使删除警报功能起作用,我需要为每个删除按钮(使用 id\'s \'delete-alert-button1\',\'delete-alert-button2\',...,\'delete -alert-buttonm\' 用于 m 个警报)。有没有一种方法可以实现这一点,这样无论用户想要发出多少警报,它都可以工作?我的直觉说,也许我可以在循环中创建回调,就像制作按钮一样。就像是:
@callback(..Input(\'delete-alert-button\'+str(customized_alerts.index(i)),\'n_clicks\')... for i in customised_alerts
作为一个快速修复,我刚刚创建了一堆回调,所以它涵盖了这么多警报。但是,如果用户创建的警报比我考虑的多,这就会成为一个问题。
标签: python callback plotly-dash dashboard