35
35
from ._utils import patch_collections_abc as _patch_collections_abc
36
36
from . import _watch
37
37
from ._utils import get_asset_path as _get_asset_path
38
+ from ._utils import get_relative_path as _get_relative_path
38
39
from ._utils import create_callback_id as _create_callback_id
39
40
from ._configs import get_combined_config , pathname_configs
40
41
from .version import __version__
@@ -1357,7 +1358,7 @@ def add_context(*args, **kwargs):
1357
1358
has_update = False
1358
1359
for i , o in enumerate (output ):
1359
1360
val = output_value [i ]
1360
- if not isinstance ( val , _NoUpdate ) :
1361
+ if val is not no_update :
1361
1362
has_update = True
1362
1363
o_id , o_prop = o .component_id , o .component_property
1363
1364
component_ids [o_id ][o_prop ] = val
@@ -1367,7 +1368,7 @@ def add_context(*args, **kwargs):
1367
1368
1368
1369
response = {"response" : component_ids , "multi" : True }
1369
1370
else :
1370
- if isinstance ( output_value , _NoUpdate ) :
1371
+ if output_value is no_update :
1371
1372
raise exceptions .PreventUpdate
1372
1373
1373
1374
response = {
@@ -1565,6 +1566,33 @@ def get_asset_url(self, path):
1565
1566
1566
1567
return asset
1567
1568
1569
+ def get_relative_path (self , path ):
1570
+ """
1571
+ Return a path with `requests_pathname_prefix` prefixed before it.
1572
+
1573
+ Use this function when specifying local URL paths that will work
1574
+ in environments regardless of what `requests_pathname_prefix` is.
1575
+
1576
+ In some deployment environments, like Dash Enterprise,
1577
+ `requests_pathname_prefix` is set to the application name,
1578
+ e.g. `my-dash-app`.
1579
+
1580
+ When working locally, `requests_pathname_prefix` might be unset and
1581
+ so a relative URL like `/page-2` can just be `/page-2`.
1582
+
1583
+ However, when the app is deployed to a URL like `/my-dash-app`, then
1584
+ `app.get_relative_path('/page-2')` will return `/my-dash-app/page-2`.
1585
+
1586
+ This can be used as an alternative to `get_asset_url` as well with
1587
+ `app.get_relative_path('/assets/logo.png')`
1588
+ """
1589
+ asset = _get_relative_path (
1590
+ self .config .requests_pathname_prefix ,
1591
+ path ,
1592
+ )
1593
+
1594
+ return asset
1595
+
1568
1596
def _setup_dev_tools (self , ** kwargs ):
1569
1597
debug = kwargs .get ("debug" , False )
1570
1598
dev_tools = self ._dev_tools = _AttributeDict ()
0 commit comments