Python Dash如何创建两个列表?

问题描述 投票:0回答:1

我正在尝试为Plotly Dash Webapp创建表。

根据数据框中的数据,我要创建下表(两列表,一侧为列名,另一侧为值):

列名|值

我正在使用下面的逻辑,但是它只是给我一张表格,其中包含一列,并将值和列名称堆叠在同一列中。

  return html.Table(
        # Header
        [html.Tr([html.Tr(col) for col in dataframe.columns])] +

        # Body
        [html.Td([
            html.Tr(dataframe.iloc[i][col]) for col in dataframe.columns
        ]) for i in range(min(len(dataframe), max_rows))]
    )

对于那些熟悉html的人,这是我想要做的:

<table>
<tr>
<td>Column Name:</td>
<td>Values:</td>
</tr>
python plotly-dash
1个回答
0
投票

您可以通过以下方式传递标头数据:

html.Th()

和实际表数据:

html.Td()

示例用法:

 ... 
            html.Table(className='table',
                children = 
                [
                    html.Tr( [html.Th('Attribute'), html.Th("Value")] )
                ] +
                [
                    html.Tr( [html.Td('OS'),         html.Td('{}'.format(get_platform()))] ),
                    html.Tr( [html.Td('#CPUs'),      html.Td('{}'.format(ps.cpu_count()))] ),
                    html.Tr( [html.Td('CPU Clock'),  html.Td('{} MHz'.format(int(ps.cpu_freq().current)))] ),
                    html.Tr( [html.Td('RAM'),       html.Td('{} GB'.format(ps.virtual_memory().total >> 30))] ),
                    html.Tr( [html.Td('#processes'), html.Td('{}'.format(len(ps.pids())))] ),
                ]
            ),
. . .

您可以检出以下文件以获取html表格,图形的用法:https://github.com/tarun27sh/dash-on-heroku/blob/master/app.py

© www.soinside.com 2019 - 2024. All rights reserved.