You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#2795 enabled you to pass a list of components to app.layout. However, this does not work when app.layout is set to a function:
import datetime
from dash import Dash, html
def layout():
return [html.H1(datetime.datetime.now())]
app = Dash(__name__)
app.layout = layout
app.run()
Gives:
Traceback (most recent call last):
File "/Users/antony_milne/Library/Application Support/JetBrains/PyCharm2024.1/scratches/scratch_51.py", line 11, in <module>
app.layout = layout
^^^^^^^^^^
File "/Users/antony_milne/Library/Application Support/hatch/env/virtual/vizro/fm3ubPZu/vizro/lib/python3.11/site-packages/dash/dash.py", line 734, in layout
[simple_clone(c) for c in layout_value._traverse_ids()],
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute '_traverse_ids'
I see that the main motivation for #2795 was that it simplified examples for beginners, so this is not such an important case because using a function for layout is already more advanced. But still I think this should probably work.
The root of the problem is that the code in Dash.layout that handles the case that layout is a function still expect it to return a single Dash component. One possible fix would be to alter this line:
gvwilson
changed the title
[BUG] Layout as list of components does not work when layout is a function
Layout as list of components does not work when layout is a function
Aug 13, 2024
Describe your context
Describe the bug
#2795 enabled you to pass a list of components to
app.layout
. However, this does not work whenapp.layout
is set to a function:Gives:
I see that the main motivation for #2795 was that it simplified examples for beginners, so this is not such an important case because using a function for
layout
is already more advanced. But still I think this should probably work.The root of the problem is that the code in
Dash.layout
that handles the case that layout is a function still expect it to return a single Dash component. One possible fix would be to alter this line:dash/dash/dash.py
Line 729 in bbd013c
This expects a single Dash component to be returned rather than a list so it works if you just wrap it in an
html.Div
.The text was updated successfully, but these errors were encountered: