-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Dash for R v0.3.0 #175
Changes from all commits
5c83f5c
d20daa8
0845184
29a3042
bbfc6cc
2e09789
c947c73
8e3c168
5d485d9
5c2ea67
cd33eba
f866d38
7e16f8d
4b99c88
2ca3f98
68be6a9
1d5ee2d
e852995
22227f6
006b6d3
93345e6
e6c460a
8c9678b
61e6dfa
ca6613c
fb05d18
85828d3
e4cedb3
cc9e06d
3733ead
2f1be58
6eddf98
a2907ba
98254a1
402969d
d7dcae7
c03c6c1
030adb4
744b696
c853cbf
7c26675
49c97da
21e78db
2c46d9f
0085036
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
Package: dash | ||
Title: An Interface to the Dash Ecosystem for Authoring Reactive Web Applications | ||
Version: 0.2.0 | ||
Authors@R: c(person("Chris", "Parmer", role = c("aut"), email = "[email protected]"), person("Ryan Patrick", "Kyle", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5829-9867"), email = "[email protected]"), person("Carson", "Sievert", role = c("aut"), comment = c(ORCID = "0000-0002-4958-2844")), person(family = "Plotly Technologies", role = "cph")) | ||
Version: 0.3.0 | ||
Authors@R: c(person("Chris", "Parmer", role = c("aut"), email = "[email protected]"), person("Ryan Patrick", "Kyle", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5829-9867"), email = "[email protected]"), person("Carson", "Sievert", role = c("aut"), comment = c(ORCID = "0000-0002-4958-2844")), person("Hammad", "Khan", role = c("aut"), email = "[email protected]"), person(family = "Plotly Technologies", role = "cph")) | ||
Description: A framework for building analytical web applications, Dash offers a pleasant and productive development experience. No JavaScript required. | ||
Depends: | ||
R (>= 3.0.2) | ||
Imports: | ||
dashHtmlComponents (== 1.0.2), | ||
dashCoreComponents (== 1.6.0), | ||
dashTable (== 4.5.1), | ||
dashCoreComponents (== 1.8.0), | ||
dashTable (== 4.6.0), | ||
R6, | ||
fiery (> 1.0.0), | ||
routr (> 0.2.0), | ||
|
@@ -32,8 +32,8 @@ Collate: | |
'print.R' | ||
'internal.R' | ||
Remotes: plotly/dash-html-components@55c3884, | ||
plotly/dash-core-components@c107e0f, | ||
plotly/dash-table@3058bd5 | ||
plotly/dash-core-components@fc153b4, | ||
plotly/dash-table@79d46ca | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
|
Large diffs are not rendered by default.
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) { | ||
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. 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. 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. 🤔 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 :) 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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ Authors: | |
\item Chris Parmer \email{[email protected]} | ||
\item Ryan Patrick Kyle \email{[email protected]} | ||
\item Carson Sievert | ||
\item Hammad Khan \email{[email protected]} | ||
} | ||
|
||
Other contributors: | ||
|
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> | ||
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. What happens if you set both 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 you set |
||
{%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" |
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