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
30 changes: 16 additions & 14 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ def __init__(
base_prefix, routes_prefix, requests_prefix = pathname_configs(
url_base_pathname, routes_pathname_prefix, requests_pathname_prefix
)
update_pages_folder = "pages" if pages_folder == "" else pages_folder

self.config = AttributeDict(
name=name,
Expand All @@ -363,9 +362,7 @@ def __init__(
assets_external_path=get_combined_config(
"assets_external_path", assets_external_path, ""
),
pages_folder=os.path.join(
flask.helpers.get_root_path(name), update_pages_folder
),
pages_folder=os.path.join(flask.helpers.get_root_path(name), pages_folder),
eager_loading=eager_loading,
include_assets_files=get_combined_config(
"include_assets_files", include_assets_files, True
Expand Down Expand Up @@ -405,8 +402,9 @@ def __init__(

_get_paths.CONFIG = self.config
_pages.CONFIG = self.config

self.pages_folder = pages_folder
self.use_pages = use_pages
self.use_pages = True if pages_folder != "pages" else use_pages
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved

# keep title as a class property for backwards compatibility
self.title = title
Expand Down Expand Up @@ -461,7 +459,6 @@ def __init__(
for plugin in plugins:
plugin.plug(self)

# amw
self.page_registry = collections.OrderedDict()

if self.server is not None:
Expand Down Expand Up @@ -844,7 +841,7 @@ def _pages_meta_tags(self):
)

return dedent(
f"""
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}" />
Expand Down Expand Up @@ -1466,7 +1463,7 @@ def _setup_server(self):
self._callback_list.extend(_callback.GLOBAL_CALLBACK_LIST)
_callback.GLOBAL_CALLBACK_LIST.clear()

# amw Update page_registry assigned with dash.register_page
# Update page_registry assigned with dash.register_page
self.page_registry = _pages.PAGE_REGISTRY.copy()

def _add_assets_resource(self, url_path, file_path):
Expand Down Expand Up @@ -2133,6 +2130,8 @@ def verify_url_part(served_part, url_part, part_name):

def _import_layouts_from_pages(self):
walk_dir = self.config.pages_folder
pages = "pages" if self.pages_folder == "" else self.pages_folder

for (root, _, files) in os.walk(walk_dir):
for file in files:
if file.startswith("_") or not file.endswith(".py"):
Expand All @@ -2143,13 +2142,14 @@ def _import_layouts_from_pages(self):
continue

page_filename = os.path.join(root, file).replace("\\", "/")
_, _, page_filename = page_filename.partition("pages/")
_, _, page_filename = page_filename.partition(pages + "/")
page_filename = page_filename.replace(".py", "").replace("/", ".")
page_module = importlib.import_module(f"pages.{page_filename}")
module_name = ".".join([pages, page_filename])
page_module = importlib.import_module(module_name)

self.page_registry = _pages.PAGE_REGISTRY.copy()
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved
if f"pages.{page_filename}" in self.page_registry:
self.page_registry[f"pages.{page_filename}"]["layout"] = getattr(
if module_name in self.page_registry:
self.page_registry[module_name]["layout"] = getattr(
page_module, "layout"
)
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -2185,8 +2185,10 @@ def router():
prevent_initial_call=True,
)
def update(pathname, search):
# updates layout on page navigation
# updates the stored page title which will trigger the clientside callback to update the app title
"""
Updates dash.page_container layout on page navigation.
Updates the stored page title which will trigger the clientside callback to update the app title
"""

# update page registry for pages that might have been added or changed in a callback
self.page_registry = _pages.PAGE_REGISTRY.copy()
Expand Down