python - Plotly Dash Multiple 显示我收到错误的原因
问题描述
我正在尝试在破折号中绘制多个图表。我从 SO.Plese 获得了一个代码。请参阅下面的链接
当我运行此处选择作为答案的相同代码时,出现错误。
NameError:名称“col_style”未定义
请看下面的代码。我可以知道我错了吗
import plotly.offline as pyo
import plotly.graph_objs as go
import plotly as py
import dash
import dash_core_components as dcc
import dash_html_components as html
fig1 = go.Scatter(y=[1,2,3])
fig2 = go.Scatter(y=[3,2,1])
plots = [fig1, fig2]
app = dash.Dash()
layout = html.Div(
[html.Div(plots[i], style=col_style[i]) for i in range(len(plots))],
style = {'margin-right': '0px'}
)
app.layout = layout
app.run_server()
我的代码目前用于绘制 10 张图像
app = dash.Dash()
app.layout = html.Div([
html.Div(html.H1(children="TEST SUIT1"),style={'textAlign': 'center','color': '#5742f5', 'fontSize': 20}),
dcc.Graph(
id = 'graph1',
figure=fig),
dcc.Graph(
id = 'graph2',
figure=fig1),
dcc.Graph(
id = 'graph3',
figure=fig2),
dcc.Graph(
id = 'graph4',
figure=fig3),
dcc.Graph(
id = 'graph5',
figure=fig4),
dcc.Graph(
id = 'graph6',
figure=fig5),
dcc.Graph(
id = 'graph7',
figure=fig6),
dcc.Graph(
id = 'graph8',
figure=fig7),
dcc.Graph(
id = 'graph9',
figure=fig8)
])
if __name__ == '__main__':
app.run_server()
进行 HLZL 建议的更改后得到的输出。我得到一个没有任何图形的空 html 文件。
Dash is running on http://127.0.0.1:8050/
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
127.0.0.1 - - [29/Jun/2021 20:11:13] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [29/Jun/2021 20:11:13] "GET /_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [29/Jun/2021 20:11:13] "GET /_dash-dependencies HTTP/1.1" 200
解决方案
以我的评论为基础:
style=col_style[i]
是 Plotly Dashhtml.Div()
函数的可选参数,如果您不想将绘图的样式更改为特定的东西(您不必这样做),可以将其删除。
即简单地使用
layout = html.Div(
[html.Div(plots[i]) for i in range(len(plots))],
style = {'margin-right': '0px'}
)
该变量col_style[i]
是 Python 字典和未进一步定义的原始作者的自定义变量。如果您想定义自定义样式,请开始阅读 Plotly Dash HTML 组件的工作原理。该style
论点使用 CSS 作为基础。
推荐阅读
- c++ - 将“this”传递给子对象
- c# - 构建 Windows 窗体项目时,“无法将类型 'int' 隐式转换为 'bool'”
- slurm - 如何使用 Slurm 对计算树进行建模?
- regex - Regex to ignore something
- angular - Extracting object item every 5 seconds in Angular
- laravel - 从具有 laravel 中主表 ID 的其他表创建查询
- regex - Remove certain letters in foma
- java - How do I rewrite this double for loop with a an if else using Java 8 lambdas?
- asp.net - QueryString 中的 + 符号在应用于会话变量时不显示
- .net - 为什么没有记录 GAC 文件夹结构?