Flexbox in dbc.Tabs

Hi, I am trying to place a dcc.Graph in dbc.Tab. The plot is supposed to go to the bottom of the screen, so I tried to use a flexbox. My attempt at that looks like this:

from dash import dcc, html, Dash
import dash_bootstrap_components as dbc
import plotly.express as px

app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = html.Div(
    style={"height": "100vh"},
    children=[
        dbc.Tabs(
            children=[
                dbc.Tab(
                    label="Graph",
                    children=[
                        dcc.Graph(
                            figure=px.line(x=[0, 1, 2, 3], y=[0, 1, 0, 1], title="Simple Graph"),
                            style={"flex": "1", "display": "flex", "flexDirection": "column"},
                        )
                    ]
                ),
                dbc.Tab(label="Other"),
            ],
        ),
    ],
)

if __name__ == "__main__":
    app.run(debug=True)

Sadly, this doesn’t work as expected. The plot is stops well before the bottom the window.

I’ve also tried without the Tabs:

from dash import dcc, html, Dash
import dash_bootstrap_components as dbc
import plotly.express as px

app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = html.Div(
    style={"height": "100vh"},
    children=[
        dcc.Graph(
            figure=px.line(x=[0, 1, 2, 3], y=[0, 1, 0, 1], title="Simple Graph"),
            style={"flex": "1", "display": "flex", "flexDirection": "column"},
        )
    ],
)

if __name__ == "__main__":
    app.run(debug=True)

This places the plot as I want it to.

From my research, I’ve found, that I need to set the height of the layers above the graph. However, I can’t seem to find a way to do that for the content of a dbc.Tab, only for the navigation content at the top. Is there a way to do that?

Any help would be greatly appreciated.

Hello @Raphael_Ratz,

Just a quick question: Are you trying to create different pages ? If so, you might use the pages feature:

In principle, yes. I will definitely look into that. Thank you very much. However, I would like to stick with the Tabs for navigation, so the problem stays the same.

I understand that. Mixing DBC and other techniques like flexbox or styles does not always work, at least in my experience.

If I remember correctly, I switched to to using html.Div() and className sometimes:

Back to the topic: The only way I found to achieve what you are after is specifying the heights manually, but I’m not very experienced with CSS.

from dash import dcc, html, Dash
import dash_bootstrap_components as dbc
import plotly.express as px

app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = html.Div(
    style={"height": "100vh"},
    children=[
        dbc.Tabs(
            children=[
                dbc.Tab(
                    label="Graph",
                    children=[
                        html.Div(
                            dcc.Graph(
                                figure=px.line(x=[0, 1, 2, 3], y=[0, 1, 0, 1], title="Simple Graph"),
                                responsive=True,
                                style={
                                    "height": "100%",
                                    "width": "100%",
                                },
                            ),
                            style={
                                "height": "calc(100vh - 42px)",      #42px seemed to be the height of the tabs themselves, at least on my system
                                "width": "100%",
                                "background-color": "blue"
                            },
                        )
                    ],
                ),
                dbc.Tab(label="Other"),
            ],
        ),
    ],
)

if __name__ == "__main__":
    app.run(debug=True, port=8052)
2 Likes

Yeah, that’s the only thing I have found so far as well. I was hoping to replace this approach with something more reliable and flexible. Regardless, thank you very much for your time and help.

1 Like

Ive built out a few of these components, take a look at Dash dash dock aslso works well with light /dark mode matching the dmc components