Skip to content

Commit

Permalink
add docs for get_asset_url
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamConnors committed Nov 11, 2024
1 parent 9566578 commit 4d580da
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dash/_get_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@


def get_asset_url(path):
"""
Return the URL for the provided `path` in the assets directory.
`dash.get_asset_url` is not compatible with Dash Snapshots.
Use `get_asset_url` on the app instance instead: `app.get_asset_url`.
See `app.get_asset_url` for more information.
"""
return app_get_asset_url(CONFIG, path)


Expand Down
29 changes: 29 additions & 0 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,35 @@ def _hash(script):
]

def get_asset_url(self, path):
"""
Return the URL for the provided `path` in the assets directory.
If `assets_external_path` is set, `get_asset_url` returns
`assets_external_path` + `assets_url_path` + `path`, where
`path` is the path passed to `get_asset_url`.
Otherwise, `get_asset_url` returns
`requests_pathname_prefix` + `assets_url_path` + `path`, where
`path` is the path passed to `get_asset_url`.
Use `get_asset_url` in an app to access assets at the correct location
in different environments. `requests_pathname_prefix` in a deployed app
on Dash Enterprise includes the app name.
For an app on Dash Enterprise called "my-app",
`app.get_asset_url("image.png")` would return:
```
/my-app/assets/image.png
```
While the same app running locally,
without `requests_pathname_prefix` set would return:
```
/assets/image.png
```
"""
return _get_paths.app_get_asset_url(self.config, path)

def get_relative_path(self, path):
Expand Down

0 comments on commit 4d580da

Please sign in to comment.