首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >dash_bootstrap_components列和行未按预期显示-仅堆叠每个项目

dash_bootstrap_components列和行未按预期显示-仅堆叠每个项目
EN

Stack Overflow用户
提问于 2021-08-11 18:51:27
回答 1查看 778关注 0票数 2

我正在尝试建立我的第一个dash应用程序,并希望使用dbc.Col和dbc.Row来组织事情。我试着在第一个名为"Equity Risk“的选项卡中构建类似这样的东西……

basic layout i'm aiming for

不幸的是,在第一个选项卡上返回的所有项目都是垂直堆叠在一起的3个项目,每个项目都占据了整个屏幕的宽度。

这是到目前为止我的代码-我不确定这是否足够的代码来诊断问题,但希望它是。我仔细检查了括号/括号,为每一列添加了宽度参数,并搜索了类似的内容,但仍然无法分辨出哪里出了问题。任何帮助都将不胜感激!

代码语言:javascript
运行
复制
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
auth = dash_auth.BasicAuth(app,USERNAME_PASSWORD_PAIRS)
server = app.server

# app layout
app.layout = html.Div([
        # header banner with titles
        html.Div(
            children=[
                html.H1('COMPANY NAME',
                        className="header-company-name"),
                html.P('HISTORICAL EARNINGS SPREAD ANALYSIS', #'Historical earnings spread analysis',
                       className='header-page-name')
            ],
            className="header-banner"
        ),
        dcc.Tabs([
            # THIS IS THE TAB THAT I'M TRYING TO ORGANIZE, BUT HAVE PROBLEMS WITH
            dcc.Tab(label='Equity Risk', children=[
                dbc.Container([
                    dbc.Row([
                        dbc.Col([
                            dbc.Row([
                                dbc.Col([
                                    # user inputs and submit button
                                    html.Div([
                                        html.Div([
                                            html.Div(children='User inputs',
                                                    className='block-title'),
                                            html.Div(children='', className='title-line'),
                                            html.Div(children='Enter a start and end date:',
                                                    className='input-title'),
                                            dcc.DatePickerRange(id='my_date_range',
                                                                min_date_allowed=df.date.min(),
                                                                max_date_allowed=df.date.max(),
                                                                start_date=datetime(2007,1,1),
                                                                end_date=datetime.today()
                                                                )
                                            ],
                                        ),
                                        html.Div(
                                            children=[
                                                html.Button(id='submit_button',
                                                            n_clicks=0,
                                                            children='Submit Inputs',
                                                            className='button')
                                            ],
                                        )
                                    ],
                                    # style={'width': '20%', 'display': 'inline-block', 'verticalAlign':'top'},
                                    className='utilities-block'
                                    )
                                ], width=3)
                            ]),
                            dbc.Row([
                                dbc.Col([
                                    # checkbox
                                    html.Div(
                                        children=[
                                            html.Div(children='Plot Adjustments',
                                                     className='block-title'),
                                            html.Div(children='', className='title-line'),
                                            dcc.RadioItems(id='plot_lines',
                                                           options=[
                                                              {'label':'Show mean and \u03C3 lines', 'value':'meanstd'},
                                                              {'label':'Show standard grid', 'value':'grid'}
                                                          ],
                                                           value='meanstd',
                                                           labelStyle={'display':'block'},
                                                           inputClassName='radio-input',
                                                           labelClassName='radio-label')
                                        ],
                                        # style={'width': '20%'},
                                        className='utilities-block'
                                    )
                                ], width=3)
                            ])
                        ], width=3),
                        dbc.Col([
                            # graph
                            html.Div(
                                children=[
                                    html.Div(children='Equity risk premium mainly between 15yr mean and -1\u03C3 in recent months',
                                             className='block-title'),
                                    html.Div(children='', className='title-line'),
                                    dcc.Graph(id='my_graph',
                                              figure=updated_figure,
                                              style={'height': '83%'},
                                              className='content-block')
                                    ],
                                # style={'width': '72%', 'display': 'inline-block', 'verticalAlign':'top', 'height':'450px'},
                                className='utilities-block'
                            )
                        ], width=9)
                    ]) # end of row
                ], fluid=True)
            ], style=tab_style, selected_style=tab_selected_style),

            # IGNORE THIS TAB.. I HAVEN'T STARTED DOING ANY GRID LAYOUT YET
            dcc.Tab(label='S&P vs P/E Ratio', children = [
               html.Div(
                   children=[
                       html.Div(children='Spread between S&P price and P/E ratio is widening',
                                className='block-title'),
                       html.Div(children='', className='title-line'),
                       dcc.Graph(id='my_sp_pe_graph',
                                 figure=sp_pe_figure,
                                 style={'height': '90%'},
                                 className='content-block')
                   ],
                   style={'width': '75%', 'display': 'inline-block', 'verticalAlign': 'top', 'height': '550px',
                          'paddingLeft': '20px'},
                   className='utilities-block'
               )
            ], style=tab_style, selected_style=tab_selected_style),
            # dcc.Tab(label='Something Else', style=tab_style, selected_style=tab_selected_style)
    ], style=tabs_style)
])
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-11 20:53:19

该问题是由于某些Col元素的width值较小引起的。没有足够的水平空间将元素放在一起,这会导致元素堆叠。

基本上发生的情况是,第一个选项卡中布局的左侧部分的列宽为3,然后实际内容位于列元素中,这些元素的width也设置为3。如果您检查布局的这一部分,您将看到这个容器的宽度非常小;宽度是行宽的1/16

因此,解决方案是要么将最内部列的宽度设置为12,要么只使用常规的div,因为外部列已经只占用了行宽的1/4

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68747475

复制
相关文章

相似问题

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