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

Fix assets to work when hosted at subdirectory #151

Merged
merged 11 commits into from
Nov 9, 2023

Conversation

antonymilne
Copy link
Contributor

@antonymilne antonymilne commented Nov 8, 2023

Description

A Vizro dashboard might be accessible through 3 different sorts of route:

  1. root level, e.g. http://www.example.com/
  2. subdomain, e.g. http://subdomain.example.com/ (as with Heroku for example)
  3. subdirectory, e.g. http://www.example.com/path/

Before this change: 1 and 2 already worked correctly but 3 did not.
Now: all should work correctly.

I've tested 1, will test 2 soon. @maxschulz-COL please can you test 3? I've bumped the version here to 0.1.6.dev2 so you can check you're using the right version when you deploy.

Important

We now have a "proper" way to alter assets_folder from its default rather than going through Vizro._user_assets_folder, since I've exposed **kwargs in Vizro().

Here's the rules for how we should write code so that paths are always correctly formed:

  • always use dash.get_relative_path to link to pages with href (see _make_page_404_layout example link)
  • always use dash.get_relative_path(f"/{STATIC_URL_PREFIX}/..") to refer to built-in assets in the static folder (see _make_page_404_layout example html.Img)
  • always use dash.get_asset_url to refer to things in the user assets folder (we don't have any examples of this at the moment outside docs)

Still to do:

  • test case 2
  • test case 3 @maxschulz-COL
  • update changelog
  • update deployment docs
  • update docs with the above rules
  • update docs about how to specify assets folder and how we can now do **kwargs in Vizro.__init__

Checklist

  • I have not referenced individuals, products or companies in any commits, directly or indirectly
  • I have not added data or restricted code in any commits, directly or indirectly
  • I have updated the docstring of any public function/class/model changed
  • I have added tests to cover my changes (if applicable)

Types of changes

  • Docs/refactoring (non-breaking change which improves codebase)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Notice

  • I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":

    • I submit this contribution under the Apache 2.0 license and represent that I am entitled to do so on behalf of myself, my employer, or relevant third parties, as applicable.
    • I certify that (a) this contribution is my original creation and / or (b) to the extent it is not my original creation, I am authorized to submit this contribution on behalf of the original creator(s) or their licensees.
    • I certify that the use of this contribution as authorized by the Apache 2.0 license does not violate the intellectual property rights of anyone else.

Copy link
Contributor

@maxschulz-COL maxschulz-COL left a comment

Choose a reason for hiding this comment

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

Great stuff! Couple of QQ

vizro-core/src/vizro/_vizro.py Show resolved Hide resolved
vizro-core/src/vizro/_vizro.py Outdated Show resolved Hide resolved
vizro-core/src/vizro/_vizro.py Show resolved Hide resolved
Copy link
Contributor

@maxschulz-COL maxschulz-COL left a comment

Choose a reason for hiding this comment

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

LG from my side!

vizro-core/docs/pages/user_guides/assets.md Outdated Show resolved Hide resolved
vizro-core/docs/pages/user_guides/assets.md Outdated Show resolved Hide resolved
@antonymilne antonymilne enabled auto-merge (squash) November 9, 2023 16:12
@antonymilne antonymilne merged commit 312e8e7 into main Nov 9, 2023
25 checks passed
@antonymilne antonymilne deleted the dev/fix-assets-pathname branch November 9, 2023 16:49
@huong-li-nguyen
Copy link
Contributor

This looks great - thanks for fixing and solving the mystery! 🚀 🔥

Looks very clean now - I also like that you don't have to provide an absolute path to the assets_folder anymore. This has been confusing for some users in the past!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report 🐛 Issue contains a bug report
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants