Skip to content

Commit 1faffe3

Browse files
committed
rm docstring too prescriptive examples
add importlib-metadata in requirements add integration test
1 parent 4b9c9d6 commit 1faffe3

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

dash/dash.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,6 @@ class Dash:
352352
add new States to the routing callback, to pass additional data to the layout
353353
functions. The syntax for this parameter is a dict of State objects:
354354
`routing_callback_inputs={"language": Input("language", "value")}`
355-
This allows things like (non-exhaustive list):
356-
* A language dropdown that will be passed to every layout function,
357-
for internationalisation
358-
* Serialising the state in URL hashes without reloading the page on every
359-
input update, and using the hash on first load / refresh
360-
* Passing a global app data store on page load
361355
"""
362356

363357
_plotlyjs_url: str

requires-all.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ flake8==3.9.2
99
flaky==3.7.0
1010
flask-talisman==0.8.1
1111
isort==4.3.21;python_version<"3.7"
12+
importlib-metadata
1213
mimesis
1314
mock==4.0.3
1415
numpy

tests/integration/multi_page/test_pages_layout.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import dash
3-
from dash import Dash, dcc, html
3+
from dash import Dash, Input, State, dcc, html
4+
from dash.dash import _ID_LOCATION
45
from dash.exceptions import NoLayoutException
56

67

@@ -179,3 +180,65 @@ def test_pala004_no_layout_exception(clear_pages_state):
179180
Dash(__name__, use_pages=True, pages_folder="pages_error")
180181

181182
assert error_msg in err.value.args[0]
183+
184+
185+
def get_routing_inputs_app():
186+
app = Dash(
187+
__name__,
188+
use_pages=True,
189+
routing_callback_inputs={
190+
"hash": State(_ID_LOCATION, "hash"),
191+
"language": Input("language", "value"),
192+
},
193+
)
194+
# Page with layout from a variable: should render and not be impacted
195+
# by routing callback inputs
196+
dash.register_page(
197+
"home",
198+
layout=html.Div("Home", id="contents"),
199+
path="/",
200+
)
201+
202+
# Page with a layout function, should see the routing callback inputs
203+
# as keyword arguments
204+
def layout1(hash: str = None, language: str = "en", **kwargs):
205+
if language == "fr":
206+
return html.Div(f"Le hash dit: {hash}", id="contents")
207+
return html.Div(f"Hash says: {hash}", id="contents")
208+
209+
dash.register_page(
210+
"function_layout",
211+
path="/function-layout",
212+
layout=layout1,
213+
)
214+
app.layout = html.Div(
215+
[
216+
dcc.Dropdown(id="language", options=["en", "fr"], value="en"),
217+
dash.page_container,
218+
]
219+
)
220+
return app
221+
222+
223+
def test_pala005_routing_inputs(dash_duo, clear_pages_state):
224+
dash_duo.start_server(get_routing_inputs_app())
225+
dash_duo.wait_for_page(url=f"http://localhost:{dash_duo.server.port}#123")
226+
dash_duo.wait_for_text_to_equal("#contents", "Home")
227+
dash_duo.wait_for_page(url=f"http://localhost:{dash_duo.server.port}/")
228+
dash_duo.wait_for_text_to_equal("#contents", "Home")
229+
dash_duo.wait_for_page(
230+
url=f"http://localhost:{dash_duo.server.port}/function-layout"
231+
)
232+
dash_duo.wait_for_text_to_equal("#contents", "Hash says:")
233+
# hash is a State therefore navigating to the same page with hash will not
234+
# re-render the layout function
235+
dash_duo.wait_for_page(
236+
url=f"http://localhost:{dash_duo.server.port}/function-layout#123"
237+
)
238+
dash_duo.wait_for_text_to_equal("#contents", "Hash says:")
239+
# Refreshing the page re-runs the layout function
240+
dash_duo.driver.refresh()
241+
dash_duo.wait_for_text_to_equal("#contents", "Hash says: #123")
242+
# Changing the language Input re-runs the layout function
243+
dash_duo.select_dcc_dropdown("#language", "fr")
244+
dash_duo.wait_for_text_to_equal("#contents", "Le hash dit: #123")

0 commit comments

Comments
 (0)