MCPcopy
hub / github.com/plotly/dash / get_relative_path

Function get_relative_path

dash/_get_paths.py:33–73  ·  view source on GitHub ↗

Return a path with `requests_pathname_prefix` prefixed before it. Use this function when specifying local URL paths that will work in environments regardless of what `requests_pathname_prefix` is. In some deployment environments, like Dash Enterprise, `requests_pathname_prefix`

(path)

Source from the content-addressed store, hash-verified

31
32
33def get_relative_path(path):
34 """
35 Return a path with `requests_pathname_prefix` prefixed before it.
36 Use this function when specifying local URL paths that will work
37 in environments regardless of what `requests_pathname_prefix` is.
38 In some deployment environments, like Dash Enterprise,
39 `requests_pathname_prefix` is set to the application name,
40 e.g. `my-dash-app`.
41 When working locally, `requests_pathname_prefix` might be unset and
42 so a relative URL like `/page-2` can just be `/page-2`.
43 However, when the app is deployed to a URL like `/my-dash-app`, then
44 `dash.get_relative_path('/page-2')` will return `/my-dash-app/page-2`.
45 This can be used as an alternative to `get_asset_url` as well with
46 `dash.get_relative_path('/assets/logo.png')`
47
48 Use this function with `dash.strip_relative_path` in callbacks that
49 deal with `dcc.Location` `pathname` routing.
50 That is, your usage may look like:
51 ```
52 app.layout = html.Div([
53 dcc.Location(id='url'),
54 html.Div(id='content')
55 ])
56 @dash.callback(Output('content', 'children'), [Input('url', 'pathname')])
57 def display_content(path):
58 page_name = dash.strip_relative_path(path)
59 if not page_name: # None or ''
60 return html.Div([
61 dcc.Link(href=dash.get_relative_path('/page-1')),
62 dcc.Link(href=dash.get_relative_path('/page-2')),
63 ])
64 elif page_name == 'page-1':
65 return chapters.page_1
66 if page_name == "page-2":
67 return chapters.page_2
68 ```
69
70 `dash.get_relative_path` is not compatible with Dash Snapshots. Use
71 `get_relative_path` on the app instance instead: `app.get_relative_path`.
72 """
73 return app_get_relative_path(CONFIG.requests_pathname_prefix, path)
74
75
76def app_get_relative_path(requests_pathname, path):

Callers 2

test_get_relative_pathFunction · 0.90
register_pageFunction · 0.85

Calls 1

app_get_relative_pathFunction · 0.85

Tested by 1

test_get_relative_pathFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…