Python Django+;plotly破折号:无法并排渲染图形
我遵循了这一点,并找到了一种方法,使图形在我的模板中并排呈现 我无法让它工作,图形的大小调整得很好,但它们一直呈现一个低于另一个的效果。我对到底出了什么问题感到困惑,因为我刚刚开始学习dash,我正在努力找出问题的根源 更新:正如在评论中提到的,我已经尝试将graph1和graph2作为一个div标记和display的子级包含在内,但是它仍然不允许两个图形彼此相邻 以下是我的文件的外观:Python Django+;plotly破折号:无法并排渲染图形,python,html,django,plotly,plotly-dash,Python,Html,Django,Plotly,Plotly Dash,我遵循了这一点,并找到了一种方法,使图形在我的模板中并排呈现 我无法让它工作,图形的大小调整得很好,但它们一直呈现一个低于另一个的效果。我对到底出了什么问题感到困惑,因为我刚刚开始学习dash,我正在努力找出问题的根源 更新:正如在评论中提到的,我已经尝试将graph1和graph2作为一个div标记和display的子级包含在内,但是它仍然不允许两个图形彼此相邻 以下是我的文件的外观: import dash_core_components as dcc import dash_html_co
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
from django_plotly_dash import DjangoDash
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
from django_plotly_dash import DjangoDash
import dash_table
import os
#external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
external_stylesheets = 'home/ubuntu/exostocksaas/staticfiles/css/style.css'
app = DjangoDash('tryout', external_stylesheets=external_stylesheets)
# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df_bar = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})
fig = px.bar(df_bar, x="Fruit", y="Amount", color="City", barmode="group")
app.layout = html.Div(children=[
# All elements from the top of the page
html.Div(children=[
html.Div(children=[
html.H1('Hello Dash'),
html.Div(''' Dash: A web application framework for Python.'''),
dcc.Graph(id='graph1',figure=fig, style={"width":500, "margin": 10,'display': 'flex'}),
html.H3('Hello Dash'),
dcc.Graph(id='graph2',figure=fig, style={"width":500, "margin": 10,'display': 'flex'}),
],
),
html.Div(children=[
html.H1('Hello Dash', style={"width":500, "margin": 0,'display': 'flex'}),
html.Div('''Dash: A web application framework for Python.''', style={"width":500, "margin": 0,'display': 'inline-block'}),
dcc.Graph(id='graph2',figure=fig, style={"width":500, "margin": 0,'display': 'flex'}),
]),
html.H1('Hello Dash'),
html.Div('''Dash: A web application framework for Python.'''),
dcc.Graph(id='graph3',figure=fig, style={"width":500, "margin": 0,'display': 'flex'}
),
], className='row'),
html.Div([
html.H1(children='Hello Dash'),
html.Div(children='''
Dash: A web application framework for Python.
'''),
dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in df_bar.columns],
data=df_bar.to_dict('records'),
sort_action='native',
filter_action='native',
export_format='csv',
style_cell={'textAlign': 'center', 'font-size' : '16px','width': '10px',
'overflow': 'hidden'
},
style_data_conditional=[
{
'if': {'row_index': 'odd'},
'backgroundColor': 'rgb(248, 248, 248)'
}
],
style_header={
'backgroundColor': 'rgb(230, 230, 230)',
'fontWeight': 'bold',
'font-size' : '20px'
}
)
], className='six columns')
])
还是不走运,我找不到办法让它工作我在本地运行了这个,它工作了。我删除了你的样式表,这样我就可以在这里使用
样式
道具显示CSS
html.Div(子类)=[
html.Div(
样式=dict(显示class='flex',高度=500),
孩子们=[
H1('Hello Dash'),
Div(“”“Dash:Python的web应用程序框架”。“”),
图(id='graph1',figure=fig,
样式={“宽度”:500,“边距”:10,'display':'flex'}),
html.H3('Hello Dash'),
图(id='graph2',figure=fig,
样式={“宽度”:500,“边距”:10,'display':'flex'}),
],
),
],className='row'),
我想你在某处也有一个CSS文件。我不知道你在设置什么样式,但我建议你使用它。我确实有一个css文件。我对如何使flexbox在这个python文件中工作以实现我试图获得的显示有点困惑。您需要一个div
,它包含两个图形作为其子图形,它应该在CSS文件中或者通过在Python中设置样式
属性来获得display:flex
属性。我想我理解你的建议@coralvanda,但它仍然没有解决问题