Skip to content
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

Pages with app.title and app.description #2826

Merged
merged 7 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).

## Added

- [#2826](https://github.com/plotly/dash/pull/2826) When using Pages, allows for `app.title` and (new) `app.description` to be used as defaults for the page title and description.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a reference to the fixed issue #2811 ?

- [#2795](https://github.com/plotly/dash/pull/2795) Allow list of components to be passed as layout.
- [2760](https://github.com/plotly/dash/pull/2760) New additions to dcc.Loading resolving multiple issues:
- [#2760](https://github.com/plotly/dash/pull/2760) New additions to dcc.Loading resolving multiple issues:
- `delay_show` and `delay_hide` props to prevent flickering during brief loading periods (similar to Dash Bootstrap Components dbc.Spinner)
- `overlay_style` for styling the loading overlay, such as setting visibility and opacity for children
- `target_components` specifies components/props triggering the loading spinner
Expand Down
21 changes: 15 additions & 6 deletions dash/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ def register_page(
order `0`

- `title`:
(string or function) The name of the page <title>. That is, what appears in the browser title.
If not supplied, will use the supplied `name` or will be inferred by module,
e.g. `pages.weekly_analytics` to `Weekly analytics`
(string or function) Specifies the page title displayed in the browser tab.
If not supplied, the app's title is used if different from the default "Dash".
Otherwise, the title is the supplied `name` or inferred from the module name.
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved
For example, `pages.weekly_analytics` is inferred as "Weekly Analytics".

- `description`:
(string or function) The <meta type="description"></meta>.
If not supplied, then nothing is supplied.
If not supplied, the app's description is used else None.
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved

- `image`:
The meta description image used by social media platforms.
Expand Down Expand Up @@ -319,10 +320,18 @@ def register_page(
)
page.update(
supplied_title=title,
title=(title if title is not None else page["name"]),
title=title
if title is not None
else CONFIG.title
if CONFIG.title != "Dash"
else page["name"],
)
page.update(
description=description if description else "",
description=description
if description
else CONFIG.description
if CONFIG.description
else "",
order=order,
supplied_order=order,
supplied_layout=layout,
Expand Down
5 changes: 5 additions & 0 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ class Dash:
functions. The syntax for this parameter is a dict of State objects:
`routing_callback_inputs={"language": Input("language", "value")}`
NOTE: the keys "pathname_" and "search_" are reserved for internal use.

:param description: Sets a default description for meta tags on Dash pages (use_pages=True).

"""

_plotlyjs_url: str
Expand Down Expand Up @@ -404,6 +407,7 @@ def __init__( # pylint: disable=too-many-statements
add_log_handler=True,
hooks: Union[RendererHooks, None] = None,
routing_callback_inputs: Optional[Dict[str, Union[Input, State]]] = None,
description=None,
**obsolete,
):
_validate.check_obsolete(obsolete)
Expand Down Expand Up @@ -458,6 +462,7 @@ def __init__( # pylint: disable=too-many-statements
title=title,
update_title=update_title,
include_pages_meta=include_pages_meta,
description=description,
)
self.config.set_read_only(
[
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/multi_page/test_pages_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,27 @@ def test_pala005_routing_inputs(dash_duo, clear_pages_state):
# Changing the language Input re-runs the layout function
dash_duo.select_dcc_dropdown("#language", "fr")
dash_duo.wait_for_text_to_equal("#contents", "Le hash dit: #123")


def get_app_title_description():
app = Dash(
__name__, use_pages=True, title="App Title", description="App Description"
)
dash.register_page("home", layout=html.Div("Home"), path="/")
dash.register_page(
"page1",
layout=html.Div("Page1"),
title="Page 1 Title",
description="Page 1 Description",
)
app.layout = html.Div(dash.page_container)
return app


def test_pala006_app_title_discription(dash_duo, clear_pages_state):
dash_duo.start_server(get_app_title_description())

assert dash.page_registry["home"]["title"] == "App Title"
assert dash.page_registry["page1"]["title"] == "Page 1 Title"
assert dash.page_registry["home"]["description"] == "App Description"
assert dash.page_registry["page1"]["description"] == "Page 1 Description"