簡體   English   中英

如何將 Plotly 'Funnel' 儀表板轉換為 Dash 儀表板?

[英]How to convert a Plotly 'Funnel' Dashboard to Dash Dashboard?

我正在嘗試將這個簡單的 plotly 漏斗儀表板轉換為 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'

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()

試試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM