python - Plotly Dash 并排图
问题描述
我正在尝试创建一个 Dash 仪表板,其中有两个并排的绘图图,一个在它们下面。这是代码:
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import dash_bootstrap_components as dbc
import numpy as np
import pandas as pd
np.random.seed(2)
df1 = pd.DataFrame(columns=['A', 'B', 'C'], data=np.random.rand(5,3))
df2 = pd.DataFrame(columns=['A', 'B', 'C'], data=np.random.rand(5,3))
df3 = pd.DataFrame(columns=['A', 'B', 'C'], data=np.random.rand(5,3))
def create_fig(df):
data = go.Table(
header=dict(
values=[str(i) for i in df.columns],
align='center'
),
cells=dict(
values=df,
align = "left",
height=45
)
)
layout = dict(
showlegend=False,
width=200
)
return dict(data=[data], layout=layout)
app = dash.Dash(external_stylesheets=['https://codepen.io/amyoshino/pen/jzXypZ.css'])
app.layout = html.Div([
html.Div(
className="row",
children=[
html.Div(
className="six columns",
children=[
html.Div(
children=dcc.Graph(id='left-top', figure=create_fig(df1))
)
]
),
html.Div(
className="six columns",
children=html.Div(
children=dcc.Graph(id='right-top', figure=create_fig(df2)),
)
)
]
),
html.Div(
className="row",
children=[
html.Div(
className="twelve columns",
children=[
html.Div(
children=dcc.Graph(id='bottom-bar-graph', figure=create_fig(df3))
)
]
)
]
)
])
if __name__ == '__main__':
app.run_server()
我尝试了一些不同的建议解决方案,但还没有成功。我也尝试过更改图形布局中的宽度和高度。 尝试解决方案 1 尝试解决方案 2
解决方案
Flexbox可以解决这个问题。div
你给的className='row'
应该有display: flex;
CSS中的样式,或者style=dict(display='flex')
如果你是内联的。
推荐阅读
- amazon-web-services - cloudformation ecs force new deployement
- survey - 在 Stack Overflow 网站内找到“2019 年开发者调查结果”调查的路径是什么?
- .net - 无法在 .Net 4.6.1 上使用 Log4Net 安装 Sentry
- exoplayer - 通过 Azure 媒体服务下载受 WideVine/FairPlay 保护的内容以供离线播放
- time-complexity - 优化的字谜函数的时间复杂度
- angular - 被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。使用 Solr 8.1.0 的 Angular 8 应用程序出错
- tcl - Tcl:将参数传递给类时评估变量值
- cmd - 虚拟环境未激活?
- reactjs - 在 Gatsby 项目中使用 SVG 文件作为 ReactComponent 的问题
- python - Python 嵌套 if