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

Add pages for multi-page app #1947

Merged
merged 66 commits into from
Jun 2, 2022
Merged
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
9b60f92
Move pages plug in from dash-labs
AnnMarieW Feb 24, 2022
4dbf472
Change how pages feature is enabled
AnnMarieW Feb 25, 2022
d304e67
tests
AnnMarieW Feb 25, 2022
2599921
new usage page - need to add a test
AnnMarieW Mar 7, 2022
4764c9c
fixed bug: page_registry can now be updated from a callback
AnnMarieW Mar 7, 2022
18655e7
Merge branch 'dev' of https://github.com/plotly/dash into add-pages
AnnMarieW Mar 7, 2022
e95f6a9
changelog
AnnMarieW Mar 7, 2022
12c7bf7
update-1 after review
AnnMarieW Mar 18, 2022
63abbe4
Update dash/dash.py
AnnMarieW Mar 18, 2022
1f38e4f
Merge branch 'add-pages' of https://github.com/AnnMarieW/dash into ad…
AnnMarieW Mar 18, 2022
9ee5ac0
added check for dash.page_container
AnnMarieW Mar 19, 2022
5f790cf
move validate pathnames
AnnMarieW Mar 20, 2022
fdf72b4
refactored interpolate_index
AnnMarieW Mar 20, 2022
9802893
fix so pages_folder can be renamed
AnnMarieW Mar 21, 2022
9d622ac
update 2 after review
AnnMarieW Mar 22, 2022
135be02
Merge branch 'dev' of https://github.com/plotly/dash into add-pages
AnnMarieW Mar 22, 2022
e459d21
fixed page_container
AnnMarieW Mar 24, 2022
a935a06
Re-run tests
AnnMarieW Mar 24, 2022
399caa5
fix tests
AnnMarieW Mar 24, 2022
fcfb61b
use pages_folder name rather than hard-coded "pages"
AnnMarieW Mar 29, 2022
0487158
added default layout with page_container
AnnMarieW Mar 30, 2022
370130b
fixed test
AnnMarieW Apr 1, 2022
ef6f57e
fixed lint
AnnMarieW Apr 1, 2022
fdf1a3d
Merge branch 'dev' of https://github.com/plotly/dash into add-pages
AnnMarieW Apr 1, 2022
aceeb9b
added test,
AnnMarieW Apr 2, 2022
8c4adc6
oops
AnnMarieW Apr 2, 2022
3bc882a
update after alexj review
AnnMarieW Apr 6, 2022
f0f81aa
Update dash/dash.py
AnnMarieW Apr 6, 2022
d3f2600
Update dash/dash.py
AnnMarieW Apr 6, 2022
c4a0b23
Update dash/dash.py
AnnMarieW Apr 6, 2022
2780bb6
Merge branch 'add-pages' of https://github.com/AnnMarieW/dash into ad…
AnnMarieW Apr 6, 2022
492bc00
added test and lint
AnnMarieW Apr 6, 2022
8f5926c
removed self.page_registry
AnnMarieW Apr 6, 2022
a205e62
more updates after review
AnnMarieW Apr 7, 2022
0ce004e
added page["relative_path"]
AnnMarieW Apr 9, 2022
556b10e
improved template matcher
AnnMarieW Apr 13, 2022
b8834b3
Merge branch 'dev' of https://github.com/plotly/dash into add-pages
AnnMarieW Apr 13, 2022
07f70ac
refactored template matcher
AnnMarieW Apr 16, 2022
5ef4d04
Merge branch 'dev' of https://github.com/plotly/dash into add-pages
AnnMarieW Apr 16, 2022
d93bad8
fixed test
AnnMarieW Apr 16, 2022
2e05833
added get_server()
AnnMarieW Apr 16, 2022
58810e2
lint
AnnMarieW Apr 16, 2022
0b1cd14
rerun test and updated examples
AnnMarieW Apr 17, 2022
a58e96b
updated get_server and added test
AnnMarieW Apr 21, 2022
0bc1856
Merge branch 'dev' of https://github.com/plotly/dash into add-pages
AnnMarieW Apr 21, 2022
053653b
temp commit
AnnMarieW Apr 22, 2022
bfbf307
temp commit and merge dev
AnnMarieW Apr 22, 2022
858e71f
lint and add tests
AnnMarieW Apr 23, 2022
5f669e9
added more error checking
AnnMarieW Apr 23, 2022
56d569b
fix tests
AnnMarieW Apr 23, 2022
09d6316
Merge branch 'dev' of https://github.com/plotly/dash into add-pages
AnnMarieW Apr 23, 2022
bbc160a
small fix
AnnMarieW Apr 24, 2022
f239b20
Allow app.layout to be callable. Update dash.get_server
AnnMarieW Apr 25, 2022
eb7293d
lint
AnnMarieW Apr 27, 2022
7b0d796
removed dash.get_server() added dash.get_app()
AnnMarieW Apr 30, 2022
5765097
fixe meta-tags
AnnMarieW May 11, 2022
cddea6b
added exception if page_registry() in callback, added tests, update …
AnnMarieW May 17, 2022
42627ca
fixed test
AnnMarieW May 18, 2022
b178e93
fixed another test
AnnMarieW May 18, 2022
e2a3363
Update dash/_configs.py
AnnMarieW Jun 1, 2022
b490523
delete usage folder
AnnMarieW Jun 1, 2022
ae47574
Merge branch 'dev' of https://github.com/plotly/dash into add-pages
AnnMarieW Jun 1, 2022
6044351
added test for no layout, minor refactoring of error messages and fun…
AnnMarieW Jun 1, 2022
a9337d4
fixed tests
AnnMarieW Jun 2, 2022
21daba0
clean up after pages no layout test, instead of before other tests
alexcjohnson Jun 2, 2022
fde2323
Merge branch 'dev' into add-pages
alexcjohnson Jun 2, 2022
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
102 changes: 40 additions & 62 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,41 @@ def _generate_meta_html(self):

return "\n ".join(tags)

def _pages_meta_tags(self):
start_page, path_variables = self._path_to_page(flask.request.path.strip("/"))
image = start_page.get("image", "")
if image:
image = self.get_asset_url(image)

title = start_page.get("title", self.title)
if callable(title):
title = title(**path_variables) if path_variables else title()

description = start_page.get("description", "")
if callable(description):
description = (
description(**path_variables) if path_variables else description()
)

return dedent(
f"""
<meta name="viewport" content="width=device-width, initial-scale=1">
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved
<title>{title}</title>
<meta name="description" content="{description}" />
<!-- Twitter Card data -->
<meta property="twitter:card" content="{description}">
<meta property="twitter:url" content="https://metatags.io/">
<meta property="twitter:title" content="{title}">
<meta property="twitter:description" content="{description}">
<meta property="twitter:image" content="{image}">
<!-- Open Graph data -->
<meta property="og:title" content="{title}" />
<meta property="og:type" content="website" />
<meta property="og:description" content="{description}" />
<meta property="og:image" content="{image}">
"""
)

# Serve the JS bundles for each package
def serve_component_suites(self, package_name, fingerprinted_path):
path_in_pkg, has_fingerprint = check_fingerprint(fingerprinted_path)
Expand Down Expand Up @@ -875,6 +910,10 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument

# use self.title instead of app.config.title for backwards compatibility
title = self.title
pages_metas = ""
if self.use_pages:
pages_metas = self._pages_meta_tags()
title = ""
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved

if self._favicon:
favicon_mod_time = os.path.getmtime(
Expand All @@ -895,7 +934,7 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument
)

index = self.interpolate_index(
metas=metas,
metas=pages_metas + metas,
title=title,
css=css,
config=config,
Expand Down Expand Up @@ -2204,67 +2243,6 @@ def update(pathname, search):
Input(_ID_STORE, "data"),
)

# Set index HTML for the meta description and page title on page load
def interpolate_index(**kwargs):
# The flask.request.path doesn't include the pathname prefix
# when inside DE Workspaces or deployed environments,
# so we don't need to call `app.strip_relative_path` on it.
start_page, path_variables = self._path_to_page(
flask.request.path.strip("/")
)
image = start_page.get("image", "")
if image:
image = self.get_asset_url(image)

title = start_page.get("title", self.title)
if callable(title):
title = title(**path_variables) if path_variables else title()

description = start_page.get("description", "")
if callable(description):
description = (
description(**path_variables)
if path_variables
else description()
)

return dedent(
f"""
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{title}</title>
<meta name="description" content="{description}" />
<!-- Twitter Card data -->
<meta property="twitter:card" content="{description}">
<meta property="twitter:url" content="https://metatags.io/">
<meta property="twitter:title" content="{title}">
<meta property="twitter:description" content="{description}">
<meta property="twitter:image" content="{image}">
<!-- Open Graph data -->
<meta property="og:title" content="{title}" />
<meta property="og:type" content="website" />
<meta property="og:description" content="{description}" />
<meta property="og:image" content="{image}">
{kwargs["metas"]}
{kwargs["favicon"]}
{kwargs["css"]}
</head>
<body>
{kwargs["app_entry"]}
<footer>
{kwargs["config"]}
{kwargs["scripts"]}
{kwargs["renderer"]}
</footer>
</body>
</html>
"""
)

self.interpolate_index = interpolate_index

def create_redirect_function(redirect_to):
def redirect():
return flask.redirect(redirect_to, code=301)
Expand Down