我遵循了这个Subplot ( Side to side ) in python Dash和How to add multiple graphs to Dash app on a single browser page?,找到了一种在我的模板中实现图形并排渲染的方法。
我不能让它工作,图形的大小调整得很好,但它们一直在渲染一个在另一个的下方。我对哪里出了问题感到困惑,而且由于我只是拿起dash,我正在努力找出问题的根本原因。
更新:正如我在评论中提到的,我已经尝试将graph1和graph2作为一个div标签和显示的子级包含在内,但是它仍然不能让两个图形彼此相邻。
下面是我的文件的样子:
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')
])还是不走运,我找不到办法让它工作
发布于 2021-01-31 23:01:13
我在本地运行了它,它起作用了。我去掉了样式表,这样我就可以使用style属性在这里显示CSS。
html.Div(children=[
html.Div(
style=dict(display='flex', height=500),
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'}),
],
),
], className='row'),https://stackoverflow.com/questions/65967824
复制相似问题