仪表板表列中的计算

时间:2019-11-29 15:59:49

标签: python pandas plot

能否请您看一下我的代码并给我一些解决问题的指南。 我从pandas DataFrame创建了一个Dash表:

html.Div([
   html.H2(children = "Tabela De Suporte Ao Planejamento",
    style = {'textAlign' : 'center',}),
]),    
html.Div([
    dash_table.DataTable(
        id='computed-table',
        columns=[{"name": i, "id": i} for i in dfplano.columns],
        editable={'UPH_BPI_vs_Perfil': True, 'Head_Disponível': True,
                  'OrderType': False, 'Unidades Pendentes': False, 'UnidadesProcessadas': False, 
                  'UPH_BPI vs Head':False, 'Qty': False},
        data=dfplano.to_dict('records'),
        style_table={'textAlign': 'center'},
        style_as_list_view=True,
        style_cell={'padding': '5px','fontSize': 12, 'textAlign': 'center'},
        style_header={
            'backgroundColor': 'white',
            'fontWeight': 'bold',
            'fontSize': 12},


    ),

        ],style={'textAlign': 'center',
                 'align-items': 'center',
                 'fontSize': 12,
                 'width': '100%',
                 'display': 'flex',
                 'align-items': 'center',
                 'justify-content': 'center'}),   

我有一个回叫,我想在其中使用来自其他列的值在“ UPH_BPI vc Head”和“ ETA Geral”列中执行计算。 为此,我创建了以下回调:

@app.callback(
    Output('computed-table', 'data'),
    [Input('computed-table', 'data_timestamp')],
    [State('computed-table', 'data')])
def update_columns(timestamp, rows):
    for row in rows:
        try:
            row['UPH_BPI_vs_Head'] = float(row['Head_Disponíve']) * float(row['UPH_BPI_vs_Perfil'])
            row['ETA Geral'] = float(row['Unidades Pendentes']) / float(row['UPH_BPI_vs_Head'])
        except:
            row['UPH_BPI vs Head'] = 'NA'
            row['ETA Geral'] = 'NA'
    return rows

我的问题是:     1-不进行计算。     2-表中的所有字段都是可编辑的,与我设置为False后相同。

能帮我吗? 谢谢

0 个答案:

没有答案