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

Updating Meta Tags #185

Merged
merged 35 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bbb17ac
meta tags example
AnnMarieW Nov 28, 2023
151078b
add infer_image function
AnnMarieW Dec 14, 2023
7dd2274
meta tags example
AnnMarieW Nov 28, 2023
4cacf7c
fixed conflicts
AnnMarieW Dec 14, 2023
4c71d52
Merge remote-tracking branch 'origin/update-meta-tags' into update-me…
AnnMarieW Dec 14, 2023
f4e98c5
remove image field, added default app.svg
AnnMarieW Dec 16, 2023
8b65397
moved meta image definition
AnnMarieW Dec 17, 2023
d5b3fe2
Update vizro-core/src/vizro/models/_page.py
AnnMarieW Dec 18, 2023
45ba59c
Merge branch 'main' into update-meta-tags
AnnMarieW Dec 18, 2023
f9f2f64
updated example app image
AnnMarieW Dec 18, 2023
e842852
removed Optional import
AnnMarieW Dec 18, 2023
859c3af
update test
AnnMarieW Dec 18, 2023
6201c73
Merge branch 'main' into update-meta-tags
AnnMarieW Dec 19, 2023
5abedca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 19, 2023
2a96b30
Update vizro-core/examples/default/app.py
AnnMarieW Dec 20, 2023
18de28f
update tests
AnnMarieW Dec 20, 2023
af0fe97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2023
d8257cf
added test_page_registry_with_image
AnnMarieW Dec 20, 2023
fd75cbb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2023
9a279cb
added test_page_registry_with_images
AnnMarieW Dec 20, 2023
f5f1c61
Update vizro-core/src/vizro/models/_dashboard.py
AnnMarieW Dec 20, 2023
ca4912d
Update vizro-core/src/vizro/models/_page.py
AnnMarieW Dec 20, 2023
b3dcce9
Update vizro-core/tests/unit/vizro/models/test_dashboard.py
AnnMarieW Dec 20, 2023
e035ecf
Apply suggestions from code review
AnnMarieW Dec 20, 2023
a4befe8
more updates after review
AnnMarieW Dec 20, 2023
b1d14c5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2023
ea1de7b
Merge branch 'main' into update-meta-tags
AnnMarieW Dec 21, 2023
f0bc461
Merge branch 'main' into update-meta-tags
AnnMarieW Dec 21, 2023
e15babc
updated schema
AnnMarieW Dec 21, 2023
14f4722
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 21, 2023
4e95ecf
Added changelog
AnnMarieW Dec 21, 2023
a5a35e4
Fixed changelog
AnnMarieW Dec 21, 2023
5181e18
Merge branch 'main' into update-meta-tags
AnnMarieW Dec 21, 2023
0c0d695
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 21, 2023
8d280f7
Update vizro-core/changelog.d/20231221_052426_amward_update_meta_tags.md
antonymilne Dec 21, 2023
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
Binary file added vizro-core/examples/assets/images/app.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions vizro-core/examples/assets/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions vizro-core/examples/default/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def create_variable_analysis():
"""Function returns a page with gapminder data to do variable analysis."""
page_variable = vm.Page(
title="Variable Analysis",
description="Analyzing population, GDP per capita and life expectancy on country and continent level",
layout=vm.Layout(
grid=[
# fmt: off
Expand Down Expand Up @@ -194,6 +195,7 @@ def create_relation_analysis():
"""Function returns a page to perform relation analysis."""
page_relation_analysis = vm.Page(
title="Relationship Analysis",
description="Investigating the interconnection between population, GDP per capita and life expectancy",
layout=vm.Layout(
grid=[[0, 0, 0, 0, 1]] + [[2, 2, 3, 3, 3]] * 4 + [[4, 4, 4, 4, 4]] * 5,
row_min_height="100px",
Expand Down Expand Up @@ -323,6 +325,7 @@ def create_continent_summary():
"""Function returns a page with markdown including images."""
page_summary = vm.Page(
title="Continent Summary",
description="Summarizing the main findings for each continent",
layout=vm.Layout(grid=[[i] for i in range(5)], row_min_height="190px", row_gap="25px"),
components=[
vm.Card(
Expand Down Expand Up @@ -415,6 +418,7 @@ def create_benchmark_analysis():

page_country = vm.Page(
title="Benchmark Analysis",
description="Discovering how the metrics differ for each country and export data for further investigation",
layout=vm.Layout(grid=[[0, 1]] * 5 + [[2, -1]], col_gap="32px", row_gap="60px"),
components=[
vm.Table(
Expand Down Expand Up @@ -496,6 +500,7 @@ def create_home_page():
"""Function returns the homepage."""
page_home = vm.Page(
title="Homepage",
description="Welcome to the Vizro demo app",
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved
layout=vm.Layout(grid=[[0, 1], [2, 3]], row_gap="16px", col_gap="24px"),
components=[
vm.Card(
Expand Down
23 changes: 22 additions & 1 deletion vizro-core/src/vizro/models/_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from functools import partial
from pathlib import Path
from typing import TYPE_CHECKING, List, Literal

import dash
Expand Down Expand Up @@ -63,13 +64,25 @@ def set_navigation_pages(cls, navigation, values):

@_log_call
def pre_build(self):
meta_image = (
self._infer_image("app")
or self._infer_image("logo")
or get_relative_path(f"/{STATIC_URL_PREFIX}/images/app.svg")
)

# Setting order here ensures that the pages in dash.page_registry preserves the order of the List[Page].
# For now the homepage (path /) corresponds to self.pages[0].
# Note redirect_from=["/"] doesn't work and so the / route must be defined separately.
for order, page in enumerate(self.pages):
path = page.path if order else "/"
dash.register_page(
module=page.id, name=page.title, path=path, order=order, layout=partial(self._make_page_layout, page)
module=page.id,
name=page.title,
path=path,
order=order,
layout=partial(self._make_page_layout, page),
description=page.description,
image=meta_image,
)
dash.register_page(module=MODULE_PAGE_404, layout=self._make_page_404_layout())

Expand Down Expand Up @@ -152,3 +165,11 @@ def _make_page_404_layout():
],
className="page_error_container",
)

def _infer_image(self, basename: str):
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved
valid_extensions = [".apng", ".avif", ".gif", ".jpeg", ".jpg", ".png", ".svg", ".webp"]
assets_folder = Path(dash.get_app().config.assets_folder)
antonymilne marked this conversation as resolved.
Show resolved Hide resolved
if assets_folder.is_dir():
for path in Path(assets_folder).rglob(f"{basename}.*"):
if path.suffix in valid_extensions:
return str(path.relative_to(assets_folder))
4 changes: 3 additions & 1 deletion vizro-core/src/vizro/models/_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List, TypedDict
from typing import List, Optional, TypedDict

from dash import Input, Output, Patch, callback, dcc, html

Expand Down Expand Up @@ -35,6 +35,7 @@ class Page(VizroBaseModel):
components (List[ComponentType]): See [ComponentType][vizro.models.types.ComponentType]. At least one component
has to be provided.
title (str): Title to be displayed.
description (str): Description for meta tags.
layout (Layout): Layout to place components in. Defaults to `None`.
controls (List[ControlType]): See [ControlType][vizro.models.types.ControlType]. Defaults to `[]`.
path (str): Path to navigate to page. Defaults to `""`.
Expand All @@ -45,6 +46,7 @@ class Page(VizroBaseModel):

components: List[ComponentType]
title: str = Field(..., description="Title to be displayed.")
description: str = Field("", description="Page description for meta tags.")
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved
layout: Layout = None # type: ignore[assignment]
controls: List[ControlType] = []
path: str = Field("", description="Path to navigate to page.")
Expand Down