You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dash多标签页跨标签输入回调问题求助

Dash应用回调优化问题

问题描述

  • 需实现一个包含2个输入、2个输出的回调,但两个输入按钮分别位于KPI Config标签页底部和KPI Viewer标签页顶部
  • 应用初始化时处于KPI Config标签页,该标签内的按钮无法被识别
  • 曾尝试拆分两个回调,但因E2P.export2pdf需多参数而使用了6个全局变量,现寻求更优解决方案

当前回调代码

@app.callback(
    [Output("kpi-viewer-tab","children"), Output("export-alert","is_open")],
    Input("start-calculations-button","n_clicks"),
    Input("dl-button","n_clicks"),
    [State("rack-boolean-switch","on"),
     State("bank-boolean-switch","on"),
     State("project-name","value"),
     State("name","value"),
     State("surname","value"),
     State("html-startdate-picker","value"),
     State("html-enddate-picker","value")]
)

def viewer_tab (click_calcul, dl_click, on_r, on_b, project_name, user_name, surname, start_dt, end_dt):
    type_request = ""
    files = []
    name = "None"
    kpi_results = dict
    StartDay = pd.Timestamp("2023-04-14T12", tz='utc')
    EndDay = pd.Timestamp("2023-04-28T12", tz='utc')
    dt_start = [StartDay + datetime.timedelta(days = 1*dayIdx) for dayIdx in range(1)]
    dt_end = [EndDay + datetime.timedelta(days = 1*dayIdx) for dayIdx in range(1)]
    tmp_idSite = "eccb5d99-f46a-4780-8853-2124b062f5ca"
    project = ""
    user = ""
    raw_data = {}
    plot_df = {}
    x_axis = []
    global calcul_in_progress
        
    if project_name is None:
        return dash.no_update
    
    if user_name is not None and surname is not None:
        surname = surname.upper()
        user_name = user_name.title()
        user = user_name+" "+surname
    
    if on_r:
        type_request = "RACK"
    elif on_b:
        type_request = "BANK"
    else:
        type_request = "RACK"
        
    for index in range (len(project_name)):
        if project_name[index] == "_":
            name = project_name[:index]
            break
    if name == "None":
        name = project_name
        
    project = name

    files = LSP.load_files(Mapping_path, TimeSeries_path, name)
    
    print(files)

    if dl_click > 0:
        E2P.export2pdf(raw_data, plot_df, x_axis, project, user, str(start_dt), str(end_dt))
        return True
    else:
        if click_calcul > 0:
            calcul_in_progress = 1
            kpi_results = RC.run_kpi_calculations(project, type_request, dt_start, dt_end, tmp_idSite, files, param_dict, kpi_calculations)
            calcul_in_progress = 0
            
            plot_df, raw_data, x_axis = RC.extract_data_from_dict(kpi_results)
            click_calcul = 0

            return TB.inside_viewer(user, plot_df, raw_data, x_axis)
        else :
            return dash.no_update

注:已知代码存在未优化和错误,后续会修正。

内容的提问来源于stack exchange,提问作者Hraesvleg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 04:33:11