Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout as list of components does not work with Dash Pages page_container #2924

Open
antonymilne opened this issue Jul 18, 2024 · 1 comment
Labels
bug something broken good first issue suitable for newcomers P3 backlog

Comments

@antonymilne
Copy link

Describe your context

dash                       2.17.1
dash_ag_grid               31.2.0
dash-bootstrap-components  1.6.0
dash-core-components       2.0.0
dash-html-components       2.0.0
dash-mantine-components    0.12.1
dash-table                 5.0.0
dash-testing-stub          0.0.2

Describe the bug

#2795 enabled you to pass a list of components to app.layout. However, this does not work with page_container.

import dash

from dash import Dash, html, page_container

app = Dash(__name__, use_pages=True, pages_folder="")
dash.register_page("/", layout=html.H1("Hello"))
app.layout = [page_container, html.H2("Stuff")]
# These work ok:
# app.layout = page_container
# app.layout = html.Div([page_container, html.H2("Stuff")])

app.run()

The first request will give the following exception:

Exception: `dash.page_container` not found in the layout

Subsequent page refreshes are ok because this check only occurs on the first request.

The problem is that the following check is failing:

dash/dash/dash.py

Line 2257 in bbd013c

if _ID_CONTENT not in self.validation_layout:

The reason for that is as follows:

assert "a" in html.Div(html.Div(id="a")) # passes
assert "a" in html.Div([html.Div(id="a")]) #passes
assert "a" in html.Div([[html.Div(id="a")]]) # FAILS - this is the relevant case here

As with #2905 probably the easiest solution is to wrap the layout in html.Div in this case so that the check passes:

assert "a" in html.Div([html.Div([html.Div(id="a")])]) # passes

Note that while #2905 is very similar it looks like the proposed fix #2915 will not solve this case. Given these two very similar issues, maybe there's a better elsewhere that would fix both (and any other similar undiscovered issues) simultaneously?

@Coding-with-Adam Coding-with-Adam added the good first issue suitable for newcomers label Jul 23, 2024
@gvwilson gvwilson added feature something new P3 backlog bug something broken labels Aug 13, 2024
@gvwilson gvwilson changed the title [BUG] Layout as list of components does not work with Dash Pages page_container Layout as list of components does not work with Dash Pages page_container Aug 13, 2024
@gvwilson gvwilson removed the feature something new label Aug 13, 2024
@kenshima4
Copy link

kenshima4 commented Dec 17, 2024

Hi dash team, I've opened a pull request for this. Can someone take a look and let me know if anything needs to be changed please? #3108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken good first issue suitable for newcomers P3 backlog
Projects
None yet
Development

No branches or pull requests

5 participants