gpt4 book ai didi

python - 如何将 Plotly 'Funnel' 仪表板转换为 Dash 仪表板?

转载 作者:行者123 更新时间:2023-12-01 06:49:55 26 4
gpt4 key购买 nike

我正在尝试将这个简单的绘图漏斗仪表板转换为 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()

输出:

enter image description here

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

关于python - 如何将 Plotly 'Funnel' 仪表板转换为 Dash 仪表板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59069101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com