【问题标题】:Remove empty left space - plotly dash bootstrap删除空白的左侧空间 - plotly dash bootstrap
【发布时间】:2022-07-01 23:00:57
【问题描述】:

我正在使用 dash 引导组件,因此我的所有组件都在我想要的布局中。 但是他们在他们的行的中心被混淆了。从左侧到我的第一张图有很多空白空间。为什么会这样?如何删除?

这是我的代码及其外观。我不知道为什么我的组件没有从最左边开始。当然,除了我的“头衔”。这应该是中心。但我的标签和图表已关闭。

from dash import Dash, dcc, html, Input, Output  # pip install dash (version 2.0.0 or higher)
import dash_bootstrap_components as dbc

app = Dash(__name__, external_stylesheets = [dbc.themes.BOOTSTRAP])
# ------------------------------------------------------------------------------
# App layout
app.layout = dbc.Container([
    dbc.Row([
        dbc.Col([
            html.H1("Title", style={'textAlign': 'center'})
        ], width=12)
    ]),

    dbc.Row([
        dbc.Col([
            html.Label("Label1"),
            dcc.Loading(id='loading0', parent_style=loading_style, children = [dcc.Graph(id='feature_plots', figure={})])
        ], width=6),
        dbc.Col([
            html.Label("Label2"),
        ], width=3)
    ]),
]
)

【问题讨论】:

    标签: plotly plotly-dash dash-bootstrap-components


    【解决方案1】:

    尝试在您的dbc.Container() 中包含fluid = True。这可能会在您的应用程序下方留下一些空间,因此您可能还希望包含style={"height": "100vh"} 以确保容器跨越整个可用垂直空间。这是我改变背景颜色的结果。因此,与您的设置相比,下面对 sn-p 的完整更改是:

    className = 'bg-success ', fluid = True, style={"height": "100vh"}
    

    应用图片:

    完整代码:

    # from dash import Dash, dcc, html, Input, Output  # pip install dash (version 2.0.0 or higher)
    # import dash_bootstrap_components as dbc
    
    from jupyter_dash import JupyterDash
    from dash import Dash, html, dcc
    import dash_bootstrap_components as dbc
    
    app = Dash(external_stylesheets = [dbc.themes.BOOTSTRAP])
    # ------------------------------------------------------------------------------
    # app  = JupyterDash(external_stylesheets=[dbc.themes.BOOTSTRAP])
    
    app.layout = dbc.Container([
        dbc.Row([
            dbc.Col([
                html.H1("Title", style={'textAlign': 'center'})
            ], width=12)
        ]),
    
        dbc.Row([
            dbc.Col([
                html.Label("Label1"),
                dcc.Loading(id='loading0',
                            # parent_style=loading_style,
                            children = [dcc.Graph(id='feature_plots', figure={})])
            ], width=6),
            dbc.Col([
                html.Label("Label2"),
            ], width=3)
        ], className = "")
    ], className = 'bg-success ', fluid = True, style={"height": "100vh"}
    )
    
    # app.run_server(mode='inline', port = 9011)  
    app.run_server(port = 9096, use_reloader = False)  
    

    【讨论】:

    • 非常感谢。那解决了它。现在我可以使用整个空间了。