Skip to content

Commit fb02bdf

Browse files
committed
Pages with app.title and app.description
1 parent f7f8fb4 commit fb02bdf

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

dash/_pages.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,14 @@ def register_page(
235235
order `0`
236236
237237
- `title`:
238-
(string or function) The name of the page <title>. That is, what appears in the browser title.
239-
If not supplied, will use the supplied `name` or will be inferred by module,
240-
e.g. `pages.weekly_analytics` to `Weekly analytics`
238+
(string or function) Specifies the page title displayed in the browser tab.
239+
If not supplied, the app's title is used if different from the default "Dash".
240+
Otherwise, the title is the supplied `name` or inferred from the module name.
241+
For example, `pages.weekly_analytics` is inferred as "Weekly Analytics".
241242
242243
- `description`:
243244
(string or function) The <meta type="description"></meta>.
244-
If not supplied, then nothing is supplied.
245+
If not supplied, the app's description is used else None.
245246
246247
- `image`:
247248
The meta description image used by social media platforms.
@@ -319,10 +320,18 @@ def register_page(
319320
)
320321
page.update(
321322
supplied_title=title,
322-
title=(title if title is not None else page["name"]),
323+
title=title
324+
if title is not None
325+
else CONFIG.title
326+
if CONFIG.title != "Dash"
327+
else page["name"],
323328
)
324329
page.update(
325-
description=description if description else "",
330+
description=description
331+
if description
332+
else CONFIG.description
333+
if CONFIG.description
334+
else "",
326335
order=order,
327336
supplied_order=order,
328337
supplied_layout=layout,

dash/dash.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ class Dash:
366366
functions. The syntax for this parameter is a dict of State objects:
367367
`routing_callback_inputs={"language": Input("language", "value")}`
368368
NOTE: the keys "pathname_" and "search_" are reserved for internal use.
369+
370+
:param description: Sets a default description for meta tags on Dash pages (use_pages=True).
371+
369372
"""
370373

371374
_plotlyjs_url: str
@@ -404,6 +407,7 @@ def __init__( # pylint: disable=too-many-statements
404407
add_log_handler=True,
405408
hooks: Union[RendererHooks, None] = None,
406409
routing_callback_inputs: Optional[Dict[str, Union[Input, State]]] = None,
410+
description=None,
407411
**obsolete,
408412
):
409413
_validate.check_obsolete(obsolete)
@@ -458,6 +462,7 @@ def __init__( # pylint: disable=too-many-statements
458462
title=title,
459463
update_title=update_title,
460464
include_pages_meta=include_pages_meta,
465+
description=description,
461466
)
462467
self.config.set_read_only(
463468
[

tests/integration/multi_page/test_pages_layout.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,27 @@ def test_pala005_routing_inputs(dash_duo, clear_pages_state):
235235
# Changing the language Input re-runs the layout function
236236
dash_duo.select_dcc_dropdown("#language", "fr")
237237
dash_duo.wait_for_text_to_equal("#contents", "Le hash dit: #123")
238+
239+
240+
def get_app_title_description():
241+
app = Dash(
242+
__name__, use_pages=True, title="App Title", description="App Description"
243+
)
244+
dash.register_page("home", layout=html.Div("Home"), path="/")
245+
dash.register_page(
246+
"page1",
247+
layout=html.Div("Page1"),
248+
title="Page 1 Title",
249+
description="Page 1 Description",
250+
)
251+
app.layout = html.Div(dash.page_container)
252+
return app
253+
254+
255+
def test_pala006_app_title_discription(dash_duo, clear_pages_state):
256+
dash_duo.start_server(get_app_title_description())
257+
258+
assert dash.page_registry["home"]["title"] == "App Title"
259+
assert dash.page_registry["page1"]["title"] == "Page 1 Title"
260+
assert dash.page_registry["home"]["description"] == "App Description"
261+
assert dash.page_registry["page1"]["description"] == "Page 1 Description"

0 commit comments

Comments
 (0)