Skip to content

Commit e277be5

Browse files
authored
Add support for adding "extra components" to an app's layout (#1700)
* Add support for adding "extra components" to an app. These are components that are automatically appended to the app's layout * Add extra components by wrapping layout in a Div
1 parent 24e91d4 commit e277be5

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

dash/dash.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ def __init__(
399399
self._layout = None
400400
self._layout_is_function = False
401401
self.validation_layout = None
402+
self._extra_components = []
402403

403404
self._setup_dev_tools()
404405
self._hot_reload = AttributeDict(
@@ -490,7 +491,15 @@ def layout(self):
490491
return self._layout
491492

492493
def _layout_value(self):
493-
return self._layout() if self._layout_is_function else self._layout
494+
from dash_html_components import Div # pylint: disable=import-outside-toplevel
495+
496+
layout = self._layout() if self._layout_is_function else self._layout
497+
498+
# Add any extra components
499+
if self._extra_components:
500+
layout = Div(children=[layout] + self._extra_components)
501+
502+
return layout
494503

495504
@layout.setter
496505
def layout(self, value):

tests/integration/callbacks/test_basic_callback.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,3 +701,40 @@ def follower_output(v):
701701
assert not dash_duo.redux_state_is_loading
702702

703703
assert dash_duo.get_logs() == []
704+
705+
706+
def test_cbsc016_extra_components_callback(dash_duo):
707+
lock = Lock()
708+
709+
app = dash.Dash(__name__)
710+
app._extra_components.append(dcc.Store(id="extra-store", data=123))
711+
712+
app.layout = html.Div(
713+
[
714+
dcc.Input(id="input", value="initial value"),
715+
html.Div(html.Div([1.5, None, "string", html.Div(id="output-1")])),
716+
]
717+
)
718+
store_data = Value("i", 0)
719+
720+
@app.callback(
721+
Output("output-1", "children"),
722+
[Input("input", "value"), Input("extra-store", "data")],
723+
)
724+
def update_output(value, data):
725+
with lock:
726+
store_data.value = data
727+
return value
728+
729+
dash_duo.start_server(app)
730+
731+
assert dash_duo.find_element("#output-1").text == "initial value"
732+
733+
input_ = dash_duo.find_element("#input")
734+
dash_duo.clear_input(input_)
735+
input_.send_keys("A")
736+
737+
wait.until(lambda: dash_duo.find_element("#output-1").text == "A", 2)
738+
739+
assert store_data.value == 123
740+
assert dash_duo.get_logs() == []

0 commit comments

Comments
 (0)