【问题标题】:Plotly Dash Table shows up in jupyter notebook but not in dash app?Plotly Dash Table 出现在 jupyter notebook 中,但没有出现在 dash 应用程序中?
【发布时间】:2020-01-17 21:19:00
【问题描述】:

我有以下创建表函数,它在 Jupyter Notebook 中相应地工作,但是当我在 Dash 应用程序中调用它时,没有任何渲染。

def create_table(dataframe):
    fig = go.Figure(data=[go.Table(
    # header=dict(values=['A Scores', 'B Scores'],
    #             line_color='darkslategray',
    #             fill_color='lightskyblue',
    #             align='left'),
    cells=dict(values=[dataframe.columns.values.tolist(), # 1st column
                       df_cohort_3.iloc[0:1].values.tolist()[0]  # 2nd column
                      ],
               line_color='darkslategray',
               fill_color='lightcyan',
               align='left'))
                        ])
    #fig.update_layout(width=500, height=600)
    return fig.show()

这是我的 Dash 逻辑:

app = dash.Dash()

app.layout = html.Div(style={'backgroundColor': colors['background']},
children=[

    #Title
    html.Div(html.H1(children="My Dashboard "))

    #Generate Dash table

    ,create_table(df_1)


    ,

                    ])

if __name__ == '__main__':
    app.run_server(debug=False, port=3005)

有什么建议吗?

【问题讨论】:

  • 您的数据框 (df_1) 是否正确加载?也许打开debug 并检查错误报告?

标签: python plotly-dash


【解决方案1】:

Dash 应用程序不使用 fig.show()。它使用 fig 对象来生成显示。您不需要调用 .show() 方法。

def create_table(dataframe):
fig = go.Figure(data=[go.Table(
cells=dict(values=[dataframe.columns.values.tolist(), # 1st column
                   df_cohort_3.iloc[0:1].values.tolist()[0]  # 2nd column
                  ],
           line_color='darkslategray',
           fill_color='lightcyan',
           align='left'))
                    ])
#fig.update_layout(width=500, height=600)
return fig

然后:

import dash_core_components as dcc
app = dash.Dash()

app.layout = html.Div(style={'backgroundColor': colors['background']},
children=[

    #Title
    html.Div(html.H1(children="My Dashboard "))

    #Generate Dash table

    ,dcc.Graph(figure=fig),


    ,

                    ])

if __name__ == '__main__':
    app.run_server(debug=False, port=3005)

【讨论】:

    猜你喜欢
    • 2021-09-14
    • 2021-12-01
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    相关资源
    最近更新 更多