-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add support for adding "extra components" to an app's layout #1700
Conversation
These are components that are automatically appended to the app's layout
Not sure what's going on with Percy 🤔 |
all green now. Ready for a look when you have a chance @alexcjohnson |
dash/dash.py
Outdated
|
||
# Add extra hidden components | ||
if self._extra_components: | ||
if not hasattr(layout, "children"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some simple apps just use app.layout = DataTable(...)
or a graph or something, that don't support children. Mostly this is just for testing purposes but maybe not always. In that case what do we do, throw an error? Wrap in html.Div
? Actually there's something nice about wrapping in a div, then we don't need to keep testing if we've already added these components into the layout, and don't need to mutate it. I can't really think of how mutating the layout would cause a problem but it makes me uneasy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you think of any cases where wrapping in a Div would break something? Any concern if the top-level is a ddk.App
or dbc.App
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would cause a problem - we're already inside a div from the react entry point
Lines 86 to 92 in a19c274
_app_entry = """ | |
<div id="react-entry-point"> | |
<div class="_dash-loading"> | |
Loading... | |
</div> | |
</div> | |
""" |
Could be nice at some point to allow the top level layout to be an array, but this would either also require wrapping in a div or would require changes to the renderer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, wrapping in a div seems like the best solution then. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b88d8a3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 💃 after adding a changelog entry.
This isn't a public feature (at least not yet), so I wasn't picturing adding a changelog for it by itself. I'll go ahead and merge this one so that I can fix up the conflicts in #1702, but I can add something more to the changelog over in that PR if you'd still like to mention this PR on its own. Thanks! |
Ok, that makes sense |
This PR is a foundational part of the coming
long_callback
PR, which will bring thelong_callback
decorator from Dash Labs to Dash. I think it may be useful in other contexts as well, so I thought I'd split it off into a separate PR for discussion.I added a new private
_extra_components
property todash.Dash
app instances that is initialized to an empty list. When components are added to this list, they are appended to the layout returned by_layout_value
.The motivation is to make it possible for
long_callback
to addInterval
andStore
components to the layout without returning them to the user and requiring the user to position them in the layout themselves.