Skip to content

Commit 24c254a

Browse files
author
Ryan Patrick Kyle
committed
📚 add documentation and some fixes
1 parent 1461ee7 commit 24c254a

File tree

7 files changed

+264
-126
lines changed

7 files changed

+264
-126
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
. venv/bin/activate
3737
pip install -e git+https://github.com/plotly/dash.git#egg=dash[testing]
3838
export PATH=$PATH:/home/circleci/.local/bin/
39+
export PERCY_ENABLE=0
3940
pytest --log-cli-level DEBUG --junitxml=test-reports/dashr.xml tests/integration/
4041
- store_artifacts:
4142
path: test-reports

NAMESPACE

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
S3method(print,dash_component)
44
export(Dash)
5-
export(dashNoUpdate)
6-
export(createCallbackId)
75
export(clientsideFunction)
6+
export(dashNoUpdate)
87
export(input)
98
export(output)
109
export(state)
11-
export(dashLogger)
1210
import(dashCoreComponents)
1311
import(dashHtmlComponents)
1412
importFrom(R6,R6Class)

R/dash.R

Lines changed: 142 additions & 105 deletions
Large diffs are not rendered by default.

R/utils.R

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,11 +951,11 @@ getIdProps <- function(output) {
951951
modtimeFromPath <- function(path, recursive = FALSE, asset_path="") {
952952
# ensure path is properly formatted
953953
path <- normalizePath(path)
954-
954+
955955
if (is.null(path)) {
956956
return(NULL)
957957
}
958-
958+
959959
if (recursive) {
960960
if (asset_path != "") {
961961
all_files <- file.info(list.files(path, recursive = TRUE))
@@ -970,12 +970,12 @@ modtimeFromPath <- function(path, recursive = FALSE, asset_path="") {
970970
}
971971
} else {
972972
# check if the path is for a directory or file, and handle accordingly
973-
if (dir.exists(path))
973+
if (dir.exists(path))
974974
modtime <- as.integer(max(file.info(list.files(path, full.names = TRUE))$mtime, na.rm=TRUE))
975975
else
976976
modtime <- as.integer(file.info(path)$mtime)
977977
}
978-
978+
979979
return(modtime)
980980
}
981981

@@ -1099,6 +1099,39 @@ dashLogger <- function(event = NULL,
10991099
}
11001100
}
11011101

1102+
#' Define a clientside callback
1103+
#'
1104+
#' Create a callback that updates the output by calling a clientside (JavaScript) function instead of an R function.
1105+
#'
1106+
#' @param namespace Character. Describes where the JavaScript function resides (Dash will look
1107+
#' for the function at `window[namespace][function_name]`.)
1108+
#' @param function_name Character. Provides the name of the JavaScript function to call.
1109+
#'
1110+
#' @details With this signature, Dash's front-end will call `window.my_clientside_library.my_function` with the current
1111+
#' values of the `value` properties of the components `my-input` and `another-input` whenever those values change.
1112+
#' Include a JavaScript file by including it your `assets/` folder. The file can be named anything but you'll need to
1113+
#' assign the function's namespace to the `window`. For example, this file might look like:
1114+
#' \preformatted{window.my_clientside_library = \{
1115+
#' my_function: function(input_value_1, input_value_2) \{
1116+
#' return (
1117+
#' parseFloat(input_value_1, 10) +
1118+
#' parseFloat(input_value_2, 10)
1119+
#' );
1120+
#' \}
1121+
#'\}
1122+
#'}
1123+
#'
1124+
#'
1125+
#' @export
1126+
#' @examples \dontrun{
1127+
#' app$callback(
1128+
#' output('output-clientside', 'children'),
1129+
#' params=list(input('input', 'value')),
1130+
#' clientsideFunction(
1131+
#' namespace = 'my_clientside_library',
1132+
#' function_name = 'my_function'
1133+
#' )
1134+
#' )}
11021135
clientsideFunction <- function(namespace, function_name) {
11031136
return(list(namespace=namespace, function_name=function_name))
11041137
}

man/Dash.Rd

Lines changed: 39 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/clientsideFunction.Rd

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/devtools/test_hard_reload.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929
)
3030
31-
app$run_server(dev_tools_hot_reload=TRUE, dev_tools_hot_reload_interval=0.1, dev_tools_silence_routes_logging=TRUE)
31+
app$run_server(dev_tools_hot_reload=TRUE, dev_tools_hot_reload_watch_interval=1, dev_tools_hot_reload_interval=0.1, dev_tools_silence_routes_logging=TRUE)
3232
"""
3333

3434

@@ -60,7 +60,6 @@ def test_rsdv002_hard_reload(dashr):
6060
)
6161
with open(app, "w") as f:
6262
f.write(old_content)
63-
time.sleep(1)
6463
dashr.wait_for_text_to_equal(
6564
"#output-serverside",
6665
"Pre-reloading test output should be NULL"

0 commit comments

Comments
 (0)