How to convert a Plotly 'Funnel' Dashboard to Dash Dashboard?

∥☆過路亽.° 提交于 2020-04-11 11:59:28

问题


I am trying to convert this simple plotly funnel dashboard to a Dash dashboard:

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

Output:

I have written the following piece of code for Dash but no luck.

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

Output:

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'

回答1:


Figure is not an attribute of dash_core_components.

We can use Graph instead.

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:


Try this one:

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


来源:https://stackoverflow.com/questions/59069101/how-to-convert-a-plotly-funnel-dashboard-to-dash-dashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!