Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33
Dash for R v0.3.0#175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Dash for R v0.3.0 #175
Changes from all commits
5c83f5cd20daa8084518429a3042bbfc6cc2e09789c947c738e3c1685d485d95c2ea67cd33ebaf866d387e16f8d4b99c882ca3f9868be6a91d5ee2de85299522227f6006b6d393345e6e6c460a8c9678b61e6dfaca6613cfb05d1885828d3e4cedb3cc9e06d3733ead2f1be586eddf98a2907ba98254a1402969dd7dcae7c03c6c1030adb4744b696c853cbf7c2667549c97da21e78db2c46d9f0085036File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -457,22 +457,25 @@ valid_seq <- function(params) { | ||
| } | ||
| } | ||
| resolve_prefix <- function(prefix, environment_var, base_pathname) { | ||
| resolvePrefix <- function(prefix, environment_var, base_pathname) { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering why this function is changed to camelCase when many other functions are snake_case. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to open a PR to migrate all functions to camelCase and variables to snake_case, which follows the generally accepted style rules for R. That will likely occur within the next week, prior to CRAN submission. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cf. https://google.github.io/styleguide/Rguide.html, though they use Pascal case instead of camel case, and maybe we should also. 🤔 Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kk, thx. Pick one, enforce it. Move on :) ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
| ||
| if (!(is.null(prefix))) { | ||
| assertthat::assert_that(is.character(prefix)) | ||
| return(prefix) | ||
| } else { | ||
| # Check environment variables | ||
| prefix_env <- Sys.getenv(environment_var) | ||
| if (prefix_env != "") { | ||
| env_base_pathname <- Sys.getenv("DASH_URL_BASE_PATHNAME") | ||
| app_name <- Sys.getenv("DASH_APP_NAME") | ||
| if (prefix_env != "") | ||
| return(prefix_env) | ||
| } else { | ||
| env_base_pathname <- Sys.getenv("DASH_URL_BASE_PATHNAME") | ||
| if (env_base_pathname != "") | ||
| return(env_base_pathname) | ||
| else | ||
| return(base_pathname) | ||
| } | ||
| else if (app_name != "") | ||
| return(sprintf("/%s/", app_name)) | ||
| else if (env_base_pathname != "") | ||
| return(env_base_pathname) | ||
| else | ||
| return(base_pathname) | ||
| } | ||
| } | ||
| @@ -1267,3 +1270,75 @@ tryCompress <- function(request, response) { | ||
| } | ||
| return(response$compress()) | ||
| } | ||
| get_relative_path <- function(requests_pathname, path) { | ||
| # Returns a path with the config setting 'requests_pathname_prefix' prefixed to | ||
| # it. This is particularly useful for apps deployed on Dash Enterprise, which makes | ||
| # it easier to serve apps under both URL prefixes and localhost. | ||
| if (requests_pathname == "/" && path == "") { | ||
| return("/") | ||
| } | ||
| else if (requests_pathname != "/" && path == "") { | ||
| return(requests_pathname) | ||
| } | ||
| else if (!startsWith(path, "/")) { | ||
| stop(sprintf(paste0("Unsupported relative path! Paths that aren't prefixed" , | ||
| "with a leading '/' are not supported. You supplied '%s'."), | ||
| path)) | ||
| } | ||
| else { | ||
| return(paste(gsub("/$", "", requests_pathname), gsub("^/", "", path), sep = "/")) | ||
| } | ||
| } | ||
| strip_relative_path <- function(requests_pathname, path) { | ||
| # Returns a relative path with the `requests_pathname_prefix` and leadings and trailing | ||
| # slashes stripped from it. This function is particularly relevant to dccLocation pathname routing. | ||
| if (is.null(path)) { | ||
| return(NULL) | ||
| } | ||
| else if ((requests_pathname != "/" && !startsWith(path, gsub("/$", "", requests_pathname))) | ||
| || (requests_pathname == "/" && !startsWith(path, "/"))) { | ||
| stop(sprintf(paste0("Unsupported relative path! Path's that are not prefixed ", | ||
| "with a leading 'requests_pathname_prefix` are not suported. ", | ||
| "You supplied '%s', and requests_pathname_prefix was '%s'."), | ||
| path, requests_pathname | ||
| )) | ||
| } | ||
| else if (requests_pathname != "/" && startsWith(path, gsub("/$", "", requests_pathname))) { | ||
| path = sub(gsub("/$", "", requests_pathname), "", path) | ||
| } | ||
| return(trimws(gsub("/", "", path))) | ||
| } | ||
| interpolate_str <- function(index_template, ...) { | ||
| # This function takes an index string, along with | ||
| # user specified keys for the html keys of the index | ||
| # and sets the default values of the keys to the | ||
| # ones specified by the keys themselves, returning | ||
| # the custom index template. | ||
| template = index_template | ||
| kwargs <- list(...) | ||
| for (name in names(kwargs)) { | ||
| key = paste0('\\{', name, '\\}') | ||
| template = sub(key, kwargs[[name]], template) | ||
| } | ||
| return(template) | ||
| } | ||
| validate_keys <- function(string) { | ||
| required_keys <- c("app_entry", "config", "scripts") | ||
| keys_present <- vapply(required_keys, function(x) grepl(x, string), logical(1)) | ||
| if (!all(keys_present)) { | ||
| stop(sprintf("Did you forget to include %s in your index string?", | ||
| paste(names(keys_present[keys_present==FALSE]), collapse = ", "))) | ||
| } else { | ||
| return(string) | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| named_app = """ | ||
| library(dash) | ||
| library(dashHtmlComponents) | ||
| app <- Dash$new() | ||
| app$title("Testing") | ||
| app$layout(htmlDiv(list(htmlDiv(id='container',children='Hello Dash for R testing')))) | ||
| app$run_server() | ||
| """ | ||
| app_with_template = """ | ||
| library(dash) | ||
| library(dashHtmlComponents) | ||
| app <- Dash$new() | ||
| string <- | ||
| "<!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| {%meta_tags%} | ||
| <title>Testing Again</title> | ||
| ||
| {%favicon%} | ||
| {%css_tags%} | ||
| </head> | ||
| <body> | ||
| {%app_entry%} | ||
| <footer> | ||
| {%config%} | ||
| {%scripts%} | ||
| </footer> | ||
| </body> | ||
| </html>" | ||
| app$index_string(string) | ||
| app$layout(htmlDiv(list(htmlDiv(id='container',children='Hello Dash for R testing')))) | ||
| app$run_server() | ||
| """ | ||
| def test_rapp001r_with_appname(dashr): | ||
| dashr.start_server(named_app) | ||
| dashr.wait_for_text_to_equal( | ||
| "#container", "Hello Dash for R testing", timeout=1 | ||
| ) | ||
| assert dashr.find_element("title").get_attribute("text") == "Testing" | ||
| def test_rapp002_r_with_template(dashr): | ||
| dashr.start_server(app_with_template) | ||
| dashr.wait_for_text_to_equal( | ||
| "#container", "Hello Dash for R testing", timeout=1 | ||
| ) | ||
| assert dashr.find_element("title").get_attribute("text") == "Testing Again" | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table version bump should also be mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in c03c6c1