You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When integrating a Dash app that uses Dash pages into a Flask app, both methods outlined here result in (differently) incorrect behaviour of the page meta tags.
To reproduce, create a file assets/app.svg and then run the following minimal apps.
Go to http://localhost:8050/dash/page. The page renders ok but if you check the source then the meta tags point to the wrong place - note the doubled up dash:
For Method 1, the code in _path_to_page cannot find the right page and so returns an empty dictionary. The reason for this is that flask.request.path.strip("/") returns dash/page rather than just page, which is the value to match against in the page registry page["path"]:
Suggested fix: use flask.request.view_args["path"] instead, which gives just page.
For Method 2, the call to app.get_asset_url already includes the requests_pathname_prefix, as does flask.request.url_root, and so you end up with this being repeated:
Suggested fix: use flask.request.host_url instead, which gives just http://localhost:8050.
These suggested fixes come about just from inspecting flask.request and looking for a suitable string. They work on the above two examples but I haven't carefully tested them, so there might be other cases that they don't solve (or worse, cases that currently work but the suggested solutions break). Hopefully someone who knows more about flask routing than me can comment on whether these are the right fixes.
This is a very small bug so I guess will not be high priority to fix, although the fix should also be quick and easy. I'd be happy to raise a PR if the above suggestions seem correct or if someone makes a better suggestion.
The text was updated successfully, but these errors were encountered:
Describe your context
Please provide us your environment, so we can easily reproduce the issue.
Describe the bug
When integrating a Dash app that uses Dash pages into a Flask app, both methods outlined here result in (differently) incorrect behaviour of the page meta tags.
To reproduce, create a file
assets/app.svg
and then run the following minimal apps.Method 1
Go to http://localhost:8050/dash/page. The page renders ok but if you check the source then the meta tags have no content:
Method 2
Go to http://localhost:8050/dash/page. The page renders ok but if you check the source then the meta tags point to the wrong place - note the doubled up
dash
:Expected behaviour
In both the above cases, the meta tag should be as follows:
Source of problem
For Method 1, the code in
_path_to_page
cannot find the right page and so returns an empty dictionary. The reason for this is thatflask.request.path.strip("/")
returnsdash/page
rather than justpage
, which is the value to match against in the page registrypage["path"]
:dash/dash/_pages.py
Line 386 in 78ebf0d
Suggested fix: use
flask.request.view_args["path"]
instead, which gives justpage
.For Method 2, the call to
app.get_asset_url
already includes therequests_pathname_prefix
, as doesflask.request.url_root
, and so you end up with this being repeated:dash/dash/_pages.py
Line 393 in 78ebf0d
Suggested fix: use
flask.request.host_url
instead, which gives justhttp://localhost:8050
.These suggested fixes come about just from inspecting
flask.request
and looking for a suitable string. They work on the above two examples but I haven't carefully tested them, so there might be other cases that they don't solve (or worse, cases that currently work but the suggested solutions break). Hopefully someone who knows more about flask routing than me can comment on whether these are the right fixes.This is a very small bug so I guess will not be high priority to fix, although the fix should also be quick and easy. I'd be happy to raise a PR if the above suggestions seem correct or if someone makes a better suggestion.
The text was updated successfully, but these errors were encountered: