首页 > 解决方案 > 以垂直格式显示列的值 - 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

关于我如何更改垂直显示的值的任何提示?提前致谢。

标签: pythonplotlydata-visualization

解决方案


   return html.Table(
        [html.Tr([html.Th(row) ])] + 
        [html.Tr(i) for i in dataframe[row].values] 

如果有人有同样的问题,发布这个


推荐阅读