将传说添加到dash datatable

发布于 2025-01-25 12:45:49 字数 879 浏览 1 评论 0原文

从以下代码开始,我想为此表格添加一个传说:

from dash import Dash, dash_table
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')

app = Dash(__name__)

app.layout = dash_table.DataTable(df.to_dict('records'), [{"name": i, "id": i} for i in df.columns])

if __name__ == '__main__':
    app.run_server(debug=True)

另请参阅: https:// .plotly.com/datatable

我想在屏幕底部有类似的东西:

说明
状态收集数据的状态。
太阳能电厂的数量是该州太阳能电厂的总数。
安装容量(MW)兆瓦的安装容量。
平均每种植物的平均兆瓦产量产量。
(GWH)每小时生成gigawatts。

Starting from the following code, I'd like to add a legend to this tabular:

from dash import Dash, dash_table
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')

app = Dash(__name__)

app.layout = dash_table.DataTable(df.to_dict('records'), [{"name": i, "id": i} for i in df.columns])

if __name__ == '__main__':
    app.run_server(debug=True)

See also: https://dash.plotly.com/datatable

I'd like to have something like this on the bottom of the screen:

ColumnExplanation
StateThe state for which the data was collected.
Number of Solar PlantsThe total number of solar plants in the state.
Installed Capacity (MW)The installed capacity in megawatts.
Average MW Per PlantThe average power production in megawatts.
Generation (GWh)Generated gigawatts per hour.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情未る 2025-02-01 12:45:49

由于该表靠近并在全显示宽度下显示,因此您可以使用Inine Block插入空间并优化列宽度。

from dash import Dash, html, dash_table
from jupyter_dash import JupyterDash
import pandas as pd

explain = ["The state for which the data was collected.",
           "The total number of solar plants in the state.",
           "The installed capacity in megawatts.",
           "The average power production in megawatts.",
           "Generated gigawatts per hour."]     

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')
df_legend = pd.DataFrame({'Column':df.columns, 'Explanation': explain})

#app = Dash(__name__)
app = JupyterDash(__name__)

app.layout = html.Div([
    html.Div(id='div1', children=[
        dash_table.DataTable(df.to_dict('records'), [{"name": i, "id": i} for i in df.columns])
    ]),
    html.Div(id='div2', children=[
        dash_table.DataTable(
        data=df_legend.to_dict('records'),
        columns=[{"name": i, "id": i} for i in df_legend.columns],
        )
    ], style={'display': 'inline-block'})
])

if __name__ == '__main__':
    app.run_server(debug=True)#, mode='inline'

Since the table is displayed close together and at full display width, you can use inine-block to insert spaces and optimize column widths.

from dash import Dash, html, dash_table
from jupyter_dash import JupyterDash
import pandas as pd

explain = ["The state for which the data was collected.",
           "The total number of solar plants in the state.",
           "The installed capacity in megawatts.",
           "The average power production in megawatts.",
           "Generated gigawatts per hour."]     

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')
df_legend = pd.DataFrame({'Column':df.columns, 'Explanation': explain})

#app = Dash(__name__)
app = JupyterDash(__name__)

app.layout = html.Div([
    html.Div(id='div1', children=[
        dash_table.DataTable(df.to_dict('records'), [{"name": i, "id": i} for i in df.columns])
    ]),
    html.Div(id='div2', children=[
        dash_table.DataTable(
        data=df_legend.to_dict('records'),
        columns=[{"name": i, "id": i} for i in df_legend.columns],
        )
    ], style={'display': 'inline-block'})
])

if __name__ == '__main__':
    app.run_server(debug=True)#, mode='inline'

enter image description here

影子是时光的心 2025-02-01 12:45:49

我找到了解决问题的解决方案。我只是添加了第二个表格作为传奇。

from dash import Dash, dash_table
import pandas as pd
from dash import html

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')

app = Dash(__name__)

explanations = ["The state for which the data was collected.", "The total number of solar plants in the state.", "The installed capacity in megawatts.", "The average power production in megawatts.", "Generated gigawatts per hour."]

app.layout = html.Div([
    dash_table.DataTable(df.to_dict('records'),
                         [{"name": i, "id": i} for i in df.columns]),
    dash_table.DataTable([{"Column": "State", "Explanation": "The state for which the data was collected."},
                          {"Column": "Number of Solar Plants", "Explanation": "The total number of solar plants in the state."},
                          {"Column": "Installed Capacity (MW)", "Explanation": "The installed capacity in megawatts."},
                          {"Column": "Average MW Per Plant", "Explanation": "The average power production in megawatts."},
                          {"Column": "Generation (GWh)", "Explanation": "Generated gigawatts per hour."},],
                           [{"name": i, "id": i} for i in ["Column", "Explanation"]]),
    html.Div(id='datatable-interactivity-container')
])

#app.layout = 

if __name__ == '__main__':
    app.run_server(debug=True)

I found a solution for my problem. I simply added a second tabular as a legend.

from dash import Dash, dash_table
import pandas as pd
from dash import html

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')

app = Dash(__name__)

explanations = ["The state for which the data was collected.", "The total number of solar plants in the state.", "The installed capacity in megawatts.", "The average power production in megawatts.", "Generated gigawatts per hour."]

app.layout = html.Div([
    dash_table.DataTable(df.to_dict('records'),
                         [{"name": i, "id": i} for i in df.columns]),
    dash_table.DataTable([{"Column": "State", "Explanation": "The state for which the data was collected."},
                          {"Column": "Number of Solar Plants", "Explanation": "The total number of solar plants in the state."},
                          {"Column": "Installed Capacity (MW)", "Explanation": "The installed capacity in megawatts."},
                          {"Column": "Average MW Per Plant", "Explanation": "The average power production in megawatts."},
                          {"Column": "Generation (GWh)", "Explanation": "Generated gigawatts per hour."},],
                           [{"name": i, "id": i} for i in ["Column", "Explanation"]]),
    html.Div(id='datatable-interactivity-container')
])

#app.layout = 

if __name__ == '__main__':
    app.run_server(debug=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文