|
117 | 117 | #' present a warning and return `NULL` if the Dash app was not loaded via `source()`
|
118 | 118 | #' if the `DASH_APP_PATH` environment variable is undefined.
|
119 | 119 | #' }
|
| 120 | +#' \item{`get_relative_path(path, requests_pathname_prefix)`}{ |
| 121 | +#' The `get_relative_path` method simplifies the handling of URLs and pathnames for apps |
| 122 | +#' running locally and on a deployment server such as Dash Enterprise. It handles the prefix |
| 123 | +#' for requesting assets similar to the `get_asset_url` method, but can also be used for URL handling |
| 124 | +#' in components such as `dccLink` or `dccLocation`. For example, `app$get_relative_url("/page/")` |
| 125 | +#' would return `/app/page/` for an app running on a deployment server. The path must be prefixed with |
| 126 | +#' a `/`. |
| 127 | +#' \describe{ |
| 128 | +#' \item{path}{Character. A path string prefixed with a leading `/` which directs at a path or asset directory.} |
| 129 | +#' \item{requests_pathname_prefix}{Character. The pathname prefix for the app on a deployed application. Defaults to the environment variable set by the server, or `""` if run locally.} |
| 130 | +#' } |
| 131 | +#' \item{`strip_relative_path(path, requests_pathname_prefix)`}{ |
| 132 | +#' The `strip_relative_path` method simplifies the handling of URLs and pathnames for apps |
| 133 | +#' running locally and on a deployment server such as Dash Enterprise. It acts almost opposite the `get_relative_path` |
| 134 | +#' method, by taking a `relative path` as an input, and returning the `path` stripped of the `requests_pathname_prefiex`, |
| 135 | +#' and any leading or trailing `/`. For example, a path string `/app/homepage/`, would be returned as |
| 136 | +#' `homepage`. This is particularly useful for `dccLocation` URL routing. |
| 137 | +#' \describe{ |
| 138 | +#' \item{path}{Character. A path string prefixed with a leading `/` and `requests_pathname_prefix` which directs at a path or asset directory.} |
| 139 | +#' \item{requests_pathname_prefix}{Character. The pathname prefix for the app on a deployed application. Defaults to the environment variable set by the server, or `""` if run locally.} |
| 140 | +#' } |
120 | 141 | #' \item{`index_string(string)`}{
|
121 | 142 | #' The `index_string` method allows the specification of a custom index by changing
|
122 | 143 | #' the default `HTML` template that is generated by the Dash UI. Meta tags, CSS, Javascript,
|
@@ -828,6 +849,24 @@ Dash <- R6::R6Class(
|
828 | 849 | },
|
829 | 850 |
|
830 | 851 | # ------------------------------------------------------------------------
|
| 852 | + # return relative asset URLs |
| 853 | + # ------------------------------------------------------------------------ |
| 854 | + |
| 855 | + get_relative_path = function(path, requests_pathname_prefix = self$config$requests_pathname_prefix) { |
| 856 | + asset = get_relative_path(requests_pathname = requests_pathname_prefix, path = path) |
| 857 | + return(asset) |
| 858 | + }, |
| 859 | + |
| 860 | + |
| 861 | + # ------------------------------------------------------------------------ |
| 862 | + # return relative asset URLs |
| 863 | + # ------------------------------------------------------------------------ |
| 864 | + |
| 865 | + strip_relative_path = function(path, requests_pathname_prefix = self$config$requests_pathname_prefix) { |
| 866 | + asset = strip_relative_path(requests_pathname = requests_pathname_prefix, path = path) |
| 867 | + return(asset) |
| 868 | + }, |
| 869 | + |
831 | 870 | # specify a custom index string
|
832 | 871 | # ------------------------------------------------------------------------
|
833 | 872 | index_string = function(string) {
|
@@ -945,7 +984,6 @@ Dash <- R6::R6Class(
|
945 | 984 | self$server$on('cycle-end', function(server, ...) {
|
946 | 985 | # handle case where assets are not present, since we can still hot reload the app itself
|
947 | 986 | #
|
948 |
| - # private$last_refresh is set after the asset_map is refreshed |
949 | 987 | # private$last_reload stores the time of the last hard or soft reload event
|
950 | 988 | # private$last_cycle will be set when the cycle-end handler terminates
|
951 | 989 | #
|
|
0 commit comments