python - 以垂直格式显示列的值 - Plotly Dash
问题描述
我对冲刺很陌生。
基于这个问题:https ://community.plotly.com/t/how-to-populate-a-dropdown-from-unique-values-in-a-pandas-data-frame/5543我正在尝试创建一个通过下拉菜单返回所选列的唯一值的表。
我的布局分区:
html.Div(
className = "section",
children = [
html.Div(className='section-title',children="Return the unique values of each column "),
html.Div(
dcc.Dropdown(
id='keyword_dropdown',
options=[{'label': i ,'value': i} for i in df.columns],
multi=True,
placeholder='Filter by column:'
),style={}),
html.Div(id='table-container')
]
)
我的功能:
def generate_vert_values_datable(dataframe,max_rows=10):
return html.Table(
[html.Tr([html.Th(col) for col in dataframe.columns])] +
[html.Tr([
html.Td(dataframe[col]) for col in dataframe.columns
]) for i in range(min(len(dataframe), max_rows))]
)
我的回调:
@app.callback(
Output('table-container','children'),
[Input('keyword_dropdown','value')]
)
def update_dropdown(drop_down_value):
if drop_down_value is None:
return None
return generate_vert_values_datable(df[drop_down_value])
我现在得到的是连接起来的值,如下所示:
当使用首选的最大行数单击下拉菜单时,我想以垂直格式显示每个值:
例如
COMMON_ASSET_TYPE:
-------------------------------------------------
SECURITY
FORWARD
ACCOUNT
MISCELLANEOUS
关于我如何更改垂直显示的值的任何提示?提前致谢。
解决方案
return html.Table(
[html.Tr([html.Th(row) ])] +
[html.Tr(i) for i in dataframe[row].values]
如果有人有同样的问题,发布这个
推荐阅读
- javascript - How to make Fabric js reactive using Vue js?
- elasticsearch - 如何将弹性搜索索引的所有文档卸载到 json 文件中?
- react-native - 如何使用原生基础将线性渐变应用到页眉。(反应原生)
- xml - Odoo 9: How to have a field displayed in edit form but not in the standard view?
- ajax - Ajax 响应让我获得了整个 html 页面
- c# - Parse.Initialize 在 Heroku 上托管的 .NET Core 2.2 上使用 Parse .NET SDK 引发 IOException
- php - 使用 updateOrCreate 方法更新一对多关系
- angular - angular universal not working even on empty project
- tensorflow - 为什么 tf.estimator.TrainSpec 中的 max_steps 会影响训练模型是否在 tensorflow 中完全导出?
- python - 从另一个包 Python 导入类