HTML Div将唯一id添加到定义(python和破折号)

HTML Div将唯一id添加到定义(python和破折号),python,web,plotly-dash,Python,Web,Plotly Dash,我正在尝试创建一个包含许多排行榜的web应用程序。我希望能够根据下拉输入更新这些表,但遇到了障碍 为了方便起见,我创建了一个def,以基于panda数据帧生成数据帧/表。我的想法是这样可以在编写web应用程序时节省空间 def make_leaderboard(df): return html.Div([ dash_table.DataTable( columns=[{"name": i, "id": i}

我正在尝试创建一个包含许多排行榜的web应用程序。我希望能够根据下拉输入更新这些表,但遇到了障碍

为了方便起见,我创建了一个def,以基于panda数据帧生成数据帧/表。我的想法是这样可以在编写web应用程序时节省空间

def make_leaderboard(df):
    return html.Div([
        dash_table.DataTable(
            columns=[{"name": i, "id": i} for i in df.columns],
            data=df.to_dict('records'),
            style_header={
                'backgroundColor': red,
                'color': 'white',
                'border': '0px',
                'font_family': 'Roboto',
                'font_size' : '11px',
                'line_height': '20px',
                'whiteSpace': 'normal',
            },
            style_cell={'padding': '5px', 'border': '0px', 'textAlign': 'center', 'font_family': 'Roboto', 'fontWeight': '100', 'font_size' : '11px', 'line_height': '20px'},
            style_cell_conditional=[
            {
            'if': {'column_id': c},
                'textAlign': 'left'
            } for c in ['']
            ],
            style_as_list_view=True,
            page_action='native',
            fixed_rows={'headers':True},
            style_table={'height': '250px', 'overflowY': 'auto'},
        ),
        html.Br([]),
        ])
我已经创建了用于筛选表的回调,但无法将回调链接到表id,因为不确定如何执行此操作,并且返回了一个错误(找不到id)。假设问题是一般定义,我无法在def中生成特定id

#row
html.Div([
    html.Div([
        html.Div([
            html.H6(['TWO POINT PERCENTAGE'],),
            html.Div(make_leaderboard(df_two_leaderboard),),
        ], className='four columns'),
        html.Div([
            html.H6(['THREE POINT PERCENTAGE'],),
            html.Div(make_leaderboard(df_three_leaderboard)),
        ], className='four columns'),
        html.Div([
            html.H6(['FREE THROW PERCENTAGE'],),
            html.Div(make_leaderboard(df_ft_leaderboard)),
        ], className='four columns'),
    ], className="row container-display",),
],
),
我可以简单地将id添加到div元素吗?在上面的示例代码中,我生成了3个表

目前,我只想更新一个表,然后希望可以添加多个表ID,以便更新web应用程序中的所有表

def make_leaderboard(df):
    return html.Div([
        dash_table.DataTable(
            columns=[{"name": i, "id": i} for i in df.columns],
            data=df.to_dict('records'),
            style_header={
                'backgroundColor': red,
                'color': 'white',
                'border': '0px',
                'font_family': 'Roboto',
                'font_size' : '11px',
                'line_height': '20px',
                'whiteSpace': 'normal',
            },
            style_cell={'padding': '5px', 'border': '0px', 'textAlign': 'center', 'font_family': 'Roboto', 'fontWeight': '100', 'font_size' : '11px', 'line_height': '20px'},
            style_cell_conditional=[
            {
            'if': {'column_id': c},
                'textAlign': 'left'
            } for c in ['']
            ],
            style_as_list_view=True,
            page_action='native',
            fixed_rows={'headers':True},
            style_table={'height': '250px', 'overflowY': 'auto'},
        ),
        html.Br([]),
        ])
回拨功能

@app.callback(
    Output(component_id='leaderboard', component_property='data'),  #believe the 'leaderboard' needs to be the unique table id
    [Input(component_id='select_position', component_property='value')]
)

def update_df_div(option_selected):
    filter_df = df_two_leaderboard[df_two_leaderboard['POS'].isin(option_selected)]
    data = filtered_df.to_dict('records')
    return data
谢谢你的帮助