【问题标题】:How to convert a Plotly 'Funnel' Dashboard to Dash Dashboard?如何将 Plotly 'Funnel' Dashboard 转换为 Dash Dashboard?
【发布时间】:2019-11-27 11:23:23
【问题描述】:

我正在尝试将这个简单的绘图漏斗仪表板转换为 Dash 仪表板:

from plotly import graph_objects as go

fig = go.Figure(go.Funnel(
    y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"],
    x = [39, 27.4, 20.6, 11, 2]))

fig.show()

输出:

我已经为 Dash 编写了以下代码,但没有运气。

import dash
import dash_core_components as dcc
import dash_html_components as html
from plotly import graph_objects as go

app = dash.Dash()


app.layout = html.Div([dcc.Figure(id='FunnelDashboard',
                    figure = {'data':[
                            go.Funnel(
                            y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"],
                            x = [39, 27.4, 20.6, 11, 2])]
                            }
                            )])

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

输出:

C:\Users\Test\Documents\Code>python Funnel_Dash.py
Traceback (most recent call last):
  File "Funnel_Dash.py", line 23, in <module>
    app.layout = html.Div([dcc.Figure(id='FunnelDashboard',
AttributeError: module 'dash_core_components' has no attribute 'Figure'

【问题讨论】:

    标签: python graph anaconda plotly-dash plotly-python


    【解决方案1】:

    Figure 不是dash_core_components 的属性。

    我们可以改用Graph

    app = dash.Dash()
    
    app.layout = html.Div([dcc.Graph(id='FunnelDashboard',
                        figure = {'data':[
                                go.Funnel(
                                y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"],
                                x = [39, 27.4, 26.6, 11, 2])]
                                }
                                )])
    if __name__ == '__main__':
        app.run_server()
    

    【讨论】:

      【解决方案2】:

      试试这个:

      app.layout=html.Div([
                          dcc.Graph(
                          id='chart1',
                          figure=fig
                      )
              ])
      

      【讨论】:

        猜你喜欢
        • 2016-01-18
        • 2020-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-16
        • 2022-12-02
        • 1970-01-01
        • 2015-09-25
        相关资源
        最近更新 更多