python - HTML Div 将唯一 id 添加到定义中(python 和破折号)
问题描述
我正在尝试创建一个包含许多排行榜的 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,这样我就可以更新网络应用程序中的所有表。
回调函数
@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
感谢您的任何帮助
解决方案
推荐阅读
- google-apps-script - 如何引用谷歌脚本中的单元格?
- excel - 单击 USPS 网站上的按钮以查找 9 位邮政编码
- c# - 部署到新位置的 ClickOnce 应用程序仍然引用旧位置进行更新
- r - 结合()和ggplot2
- python - 如何使用 Kivy UrlRequest 发出补丁请求
- bash - exec和flock如何在bash脚本中协同工作
- ruby-on-rails - Rails 6:ActionText 附加图像未在 _blob 部分模板中呈现
- java - 无法使用 ZeroCode 在 Kafka 主题上发布 json 消息
- scala - 如何抽象效果并将 ContextShift 与 Scala Cats 一起使用?
- regex - 使用正则表达式 Jmeter 从 Json 获取密钥