首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django + plotly-dash:无法并排呈现图形

Django + plotly-dash:无法并排呈现图形
EN

Stack Overflow用户
提问于 2021-01-30 20:15:22
回答 1查看 432关注 0票数 0

我遵循了这个Subplot ( Side to side ) in python DashHow to add multiple graphs to Dash app on a single browser page?,找到了一种在我的模板中实现图形并排渲染的方法。

我不能让它工作,图形的大小调整得很好,但它们一直在渲染一个在另一个的下方。我对哪里出了问题感到困惑,而且由于我只是拿起dash,我正在努力找出问题的根本原因。

更新:正如我在评论中提到的,我已经尝试将graph1和graph2作为一个div标签和显示的子级包含在内,但是它仍然不能让两个图形彼此相邻。

下面是我的文件的样子:

代码语言:javascript
复制
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')
    
])

还是不走运,我找不到办法让它工作

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-31 23:01:13

我在本地运行了它,它起作用了。我去掉了样式表,这样我就可以使用style属性在这里显示CSS。

代码语言:javascript
复制
    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'),
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65967824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档