|
13 | 13 | #' assets_ignore = '',
|
14 | 14 | #' serve_locally = TRUE,
|
15 | 15 | #' meta_tags = NULL,
|
16 |
| -#' routes_pathname_prefix = '/', |
17 |
| -#' requests_pathname_prefix = '/', |
| 16 | +#' url_base_pathname = '/', |
| 17 | +#' routes_pathname_prefix = NULL, |
| 18 | +#' requests_pathname_prefix = NULL, |
18 | 19 | #' external_scripts = NULL,
|
19 | 20 | #' external_stylesheets = NULL,
|
20 | 21 | #' suppress_callback_exceptions = FALSE
|
|
35 | 36 | #' `assets_ignore` \tab \tab Character. A regular expression, to match assets to omit from
|
36 | 37 | #' immediate loading. Ignored files will still be served if specifically requested. You
|
37 | 38 | #' cannot use this to prevent access to sensitive files. \cr
|
38 |
| -#' `serve_locally` \tab \tab Whether to serve HTML dependencies locally or |
| 39 | +#' `serve_locally` \tab \tab Logical. Whether to serve HTML dependencies locally or |
39 | 40 | #' remotely (via URL).\cr
|
40 | 41 | #' `meta_tags` \tab \tab List of lists. HTML `<meta>`tags to be added to the index page.
|
41 | 42 | #' Each list element should have the attributes and values for one tag, eg:
|
42 | 43 | #' `list(name = 'description', content = 'My App')`.\cr
|
43 |
| -#' `routes_pathname_prefix` \tab \tab a prefix applied to the backend routes.\cr |
44 |
| -#' `requests_pathname_prefix` \tab \tab a prefix applied to request endpoints |
45 |
| -#' made by Dash's front-end.\cr |
46 |
| -#' `external_scripts` \tab \tab An optional list of valid URLs from which |
| 44 | +#' `url_base_pathname` \tab \tab Character. A local URL prefix to use app-wide. Default is |
| 45 | +#' `/`. Both `requests_pathname_prefix` and `routes_pathname_prefix` default to `url_base_pathname`. |
| 46 | +#' Environment variable is `DASH_URL_BASE_PATHNAME`.\cr |
| 47 | +#' `routes_pathname_prefix` \tab \tab Character. A prefix applied to the backend routes. |
| 48 | +#' Environment variable is `DASH_ROUTES_PATHNAME_PREFIX`.\cr |
| 49 | +#' `requests_pathname_prefix` \tab \tab Character. A prefix applied to request endpoints |
| 50 | +#' made by Dash's front-end. Environment variable is `DASH_REQUESTS_PATHNAME_PREFIX`.\cr |
| 51 | +#' `external_scripts` \tab \tab List. An optional list of valid URLs from which |
47 | 52 | #' to serve JavaScript source for rendered pages.\cr
|
48 |
| -#' `external_stylesheets` \tab \tab An optional list of valid URLs from which |
| 53 | +#' `external_stylesheets` \tab \tab List. An optional list of valid URLs from which |
49 | 54 | #' to serve CSS for rendered pages.\cr
|
50 |
| -#' `suppress_callback_exceptions` \tab \tab Whether to relay warnings about |
| 55 | +#' `suppress_callback_exceptions` \tab \tab Logical. Whether to relay warnings about |
51 | 56 | #' possible layout mis-specifications when registering a callback.
|
52 | 57 | #' }
|
53 | 58 | #'
|
|
101 | 106 | #' values given their names. It is only available from within a callback;
|
102 | 107 | #' attempting to use this method outside of a callback will result in a warning.
|
103 | 108 | #' }
|
| 109 | +#' \item{`get_asset_url(asset_path, prefix)`}{ |
| 110 | +#' The `get_asset_url` method permits retrieval of an asset's URL given its filename. |
| 111 | +#' For example, `app$get_asset_url('style.css')` should return `/assets/style.css` when |
| 112 | +#' `assets_folder = 'assets'`. By default, the prefix is the value of `requests_pathname_prefix`, |
| 113 | +#' but this is configurable via the `prefix` parameter. Note: this method will |
| 114 | +#' present a warning and return `NULL` if the Dash app was not loaded via `source()` |
| 115 | +#' if the `DASH_APP_PATH` environment variable is undefined. |
| 116 | +#' } |
104 | 117 | #' \item{`run_server(host = Sys.getenv('DASH_HOST', "127.0.0.1"),
|
105 | 118 | #' port = Sys.getenv('DASH_PORT', 8050), block = TRUE, showcase = FALSE, ...)`}{
|
106 | 119 | #' The `run_server` method has 13 formal arguments, several of which are optional:
|
@@ -169,6 +182,7 @@ Dash <- R6::R6Class(
|
169 | 182 | assets_ignore = '',
|
170 | 183 | serve_locally = TRUE,
|
171 | 184 | meta_tags = NULL,
|
| 185 | + url_base_pathname = "/", |
172 | 186 | routes_pathname_prefix = NULL,
|
173 | 187 | requests_pathname_prefix = NULL,
|
174 | 188 | external_scripts = NULL,
|
@@ -199,8 +213,8 @@ Dash <- R6::R6Class(
|
199 | 213 | private$in_viewer <- FALSE
|
200 | 214 |
|
201 | 215 | # config options
|
202 |
| - self$config$routes_pathname_prefix <- resolve_prefix(routes_pathname_prefix, "DASH_ROUTES_PATHNAME_PREFIX") |
203 |
| - self$config$requests_pathname_prefix <- resolve_prefix(requests_pathname_prefix, "DASH_REQUESTS_PATHNAME_PREFIX") |
| 216 | + self$config$routes_pathname_prefix <- resolve_prefix(routes_pathname_prefix, "DASH_ROUTES_PATHNAME_PREFIX", url_base_pathname) |
| 217 | + self$config$requests_pathname_prefix <- resolve_prefix(requests_pathname_prefix, "DASH_REQUESTS_PATHNAME_PREFIX", url_base_pathname) |
204 | 218 | self$config$external_scripts <- external_scripts
|
205 | 219 | self$config$external_stylesheets <- external_stylesheets
|
206 | 220 |
|
@@ -706,13 +720,13 @@ Dash <- R6::R6Class(
|
706 | 720 | # ------------------------------------------------------------------------
|
707 | 721 | # return asset URLs
|
708 | 722 | # ------------------------------------------------------------------------
|
709 |
| - get_asset_url = function(asset_path, prefix = "/") { |
| 723 | + get_asset_url = function(asset_path, prefix = self$config$requests_pathname_prefix) { |
710 | 724 | app_root_path <- Sys.getenv("DASH_APP_PATH")
|
711 | 725 |
|
712 | 726 | if (app_root_path == "" && getAppPath() != FALSE) {
|
713 | 727 | # app loaded via source(), root path is known
|
714 | 728 | app_root_path <- dirname(private$app_root_path)
|
715 |
| - } else { |
| 729 | + } else if (getAppPath() == FALSE) { |
716 | 730 | # app not loaded via source(), env var not set, no reliable way to ascertain root path
|
717 | 731 | warning("application not started via source(), and DASH_APP_PATH environment variable is undefined. get_asset_url returns NULL since root path cannot be reliably identified.")
|
718 | 732 | return(NULL)
|
@@ -954,6 +968,7 @@ Dash <- R6::R6Class(
|
954 | 968 | assets_folder = NULL,
|
955 | 969 | assets_url_path = NULL,
|
956 | 970 | assets_ignore = NULL,
|
| 971 | + url_base_pathname = NULL, |
957 | 972 | routes_pathname_prefix = NULL,
|
958 | 973 | requests_pathname_prefix = NULL,
|
959 | 974 | suppress_callback_exceptions = NULL,
|
|
0 commit comments