Add support for adding "extra components" to an app's layout#1700
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.
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.
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.
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
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.
Ok, wrapping in a div seems like the best solution then. Thanks!
alexcjohnson
left a comment
There was a problem hiding this comment.
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_callbackPR, which will bring thelong_callbackdecorator 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_componentsproperty todash.Dashapp 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_callbackto addIntervalandStorecomponents to the layout without returning them to the user and requiring the user to position them in the layout themselves.