mirror of
https://github.com/rstudio/shiny.git
synced 2026-01-11 16:08:19 -05:00
Compare commits
25 Commits
ui-docs-re
...
update-new
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fba4680734 | ||
|
|
540d68ed9f | ||
|
|
1ad49b153c | ||
|
|
15885cbb5f | ||
|
|
b6979d135c | ||
|
|
d4b19820a4 | ||
|
|
8d529095a7 | ||
|
|
77f9052ab5 | ||
|
|
9fcc1fe8ad | ||
|
|
5d30b55372 | ||
|
|
78d77ce373 | ||
|
|
2cae04186b | ||
|
|
59bddea1e9 | ||
|
|
d6bd3d9f9b | ||
|
|
8eb7b056f2 | ||
|
|
40ae9a903e | ||
|
|
5b6c80d4b2 | ||
|
|
fd7518018c | ||
|
|
5c03326a8c | ||
|
|
2c82ee0235 | ||
|
|
ac84be956a | ||
|
|
0fb154cc1e | ||
|
|
837e8d33f6 | ||
|
|
3365bfc395 | ||
|
|
135fe21278 |
@@ -1,7 +1,7 @@
|
||||
Package: shiny
|
||||
Type: Package
|
||||
Title: Web Application Framework for R
|
||||
Version: 1.7.1.9002
|
||||
Version: 1.7.1.9003
|
||||
Authors@R: c(
|
||||
person("Winston", "Chang", role = c("aut", "cre"), email = "winston@rstudio.com", comment = c(ORCID = "0000-0002-1576-2126")),
|
||||
person("Joe", "Cheng", role = "aut", email = "joe@rstudio.com"),
|
||||
@@ -105,7 +105,6 @@ Suggests:
|
||||
ggplot2,
|
||||
reactlog (>= 1.0.0),
|
||||
magrittr,
|
||||
shinytest (>= 1.4.0.9003),
|
||||
yaml,
|
||||
future,
|
||||
dygraphs,
|
||||
@@ -202,8 +201,10 @@ Collate:
|
||||
'version_selectize.R'
|
||||
'version_strftime.R'
|
||||
'viewer.R'
|
||||
RoxygenNote: 7.1.2
|
||||
RoxygenNote: 7.2.0
|
||||
Encoding: UTF-8
|
||||
Roxygen: list(markdown = TRUE)
|
||||
RdMacros: lifecycle
|
||||
Config/testthat/edition: 3
|
||||
Config/Needs/check:
|
||||
rstudio/shinytest2
|
||||
|
||||
27
NEWS.md
27
NEWS.md
@@ -1,22 +1,47 @@
|
||||
shiny 1.7.1.9001
|
||||
shiny development
|
||||
================
|
||||
|
||||
## Full changelog
|
||||
|
||||
### Breaking changes
|
||||
|
||||
### Minor new features and improvements
|
||||
|
||||
* Shiny's internal HTML dependencies are now mounted dynamically instead of statically. (#3537)
|
||||
|
||||
* HTML dependencies that are sent to dynamic UI now have better type checking, and no longer require a `dep.src.href` field. (#3537)
|
||||
|
||||
* Default for `ref` input in `runGithub()` changed from `"master"` to `"HEAD"`. (#3346)
|
||||
|
||||
* When taking a test snapshot, the sort order of the json keys of the `input`, `output`, and `export` fields is currently sorted using the locale of the machine. This can lead to inconsistent test snapshot results. To opt-in to a consistent ordering of snapshot fields with `{shinytest}`, please set the global option `options(shiny.snapshotsortc = TRUE)`. `{shinytest2}` users do not need to set this value. (#3515)
|
||||
|
||||
* The auto-reload feature (`options(shiny.autoreload=TRUE)`) was not being activated by `devmode(TRUE)`, despite a console message asserting that it was. (#3620)
|
||||
|
||||
* Add `shiny.mathjax.url` and `shiny.mathjax.config` options for configuring the MathJax URL used by `withMathJax`. Thanks, @Neutron3529! (#3639)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Closed tidyverse/dplyr#5552: Compatibility of dplyr 1.0 (and rlang chained errors in general) with `req()`, `validate()`, and friends.
|
||||
|
||||
* Closed #1545: `insertUI()` now executes `<script>` tags. (#3630)
|
||||
|
||||
* Closed #2955: Input and output bindings previously attempted to use `el['data-input-id']`, but that never worked. They now use `el.getAttribute('data-input-id')` instead. (#3538)
|
||||
|
||||
* Closed tidyverse/dplyr#6154: Values from an `actionButton()` had S3 classes in the incorrect order.
|
||||
|
||||
* Fixed a bug where updating an input value without a corresponding Input binding element did not trigger a JavaScript `shiny:inputchanged` event. Now, if no Input binding element is found, the `shiny:inputchanged` event is triggered on `window.document`. (#3584)
|
||||
|
||||
* Restored the previous behavior of automatically guessing the `Content-Type` header for `downloadHandler` functions when no explicit `contentType` argument is supplied. (#3393)
|
||||
|
||||
* Closed #3619: In R 4.2, `splitLayout()` raised warnings about incorrect length in an `if` statement. (Thanks to @dmenne, #3625)
|
||||
|
||||
* Closed #2297: If an error occurred in parsing a value in a bookmark query string, an error would be thrown and nothing would be restored. Now a message is displayed and that value is ignored. (Thanks to @daattali, #3385)
|
||||
|
||||
* `fileInput()` can set the `capture` attribute to facilitates user access to a device's media capture mechanism, such as a camera, or microphone, from within a file upload control ([W3C HTML Media Capture](https://www.w3.org/TR/html-media-capture/)). (Thanks to khaled-alshamaa, #3481)
|
||||
|
||||
* Fixed rstudio/shinytest2#222: When restoring a context (i.e., bookmarking) from a URL, Shiny now better handles a trailing `=` after `_inputs_` and `_values_`. (#3648)
|
||||
|
||||
|
||||
shiny 1.7.1
|
||||
===========
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
#' 2: app.R : Main application file
|
||||
#' 3: R/example.R : Helper file with R code
|
||||
#' 4: R/example-module.R : Example module
|
||||
#' 5: tests/shinytest/ : Tests using the shinytest package
|
||||
#' 6: tests/testthat/ : Tests using the testthat package
|
||||
#' 5: tests/testthat/ : Tests using the testthat and shinytest2 package
|
||||
#' ```
|
||||
#'
|
||||
#' If option 1 is selected, the full example application including the
|
||||
@@ -24,13 +23,11 @@
|
||||
#' | |- example-module.R
|
||||
#' | `- example.R
|
||||
#' `- tests
|
||||
#' |- shinytest.R
|
||||
#' |- shinytest
|
||||
#' | `- mytest.R
|
||||
#' |- testthat.R
|
||||
#' `- testthat
|
||||
#' |- test-examplemodule.R
|
||||
#' |- test-server.R
|
||||
#' |- test-shinytest2.R
|
||||
#' `- test-sort.R
|
||||
#' ```
|
||||
#'
|
||||
@@ -45,20 +42,20 @@
|
||||
#' * `tests/` contains various tests for the application. You may
|
||||
#' choose to use or remove any of them. They can be executed by the
|
||||
#' [runTests()] function.
|
||||
#' * `tests/shinytest.R` is a test runner for test files in the
|
||||
#' `tests/shinytest/` directory.
|
||||
#' * `tests/shinytest/mytest.R` is a test that uses the
|
||||
#' [shinytest](https://rstudio.github.io/shinytest/) package to do
|
||||
#' snapshot-based testing.
|
||||
#' * `tests/testthat.R` is a test runner for test files in the
|
||||
#' `tests/testthat/` directory using the [testthat](https://testthat.r-lib.org/) package.
|
||||
#' `tests/testthat/` directory using the
|
||||
#' [shinytest2](https://rstudio.github.io/shinytest2/reference/test_app.html)
|
||||
#' package.
|
||||
#' * `tests/testthat/test-examplemodule.R` is a test for an application's module server function.
|
||||
#' * `tests/testthat/test-server.R` is a test for the application's server code
|
||||
#' * `tests/testthat/test-shinytest2.R` is a test that uses the
|
||||
#' [shinytest2](https://rstudio.github.io/shinytest2/) package to do
|
||||
#' snapshot-based testing.
|
||||
#' * `tests/testthat/test-sort.R` is a test for a supporting function in the `R/` directory.
|
||||
#'
|
||||
#' @param path Path to create new shiny application template.
|
||||
#' @param examples Either one of "default", "ask", "all", or any combination of
|
||||
#' "app", "rdir", "module", "shinytest", and "testthat". In an
|
||||
#' "app", "rdir", "module", and "tests". In an
|
||||
#' interactive session, "default" falls back to "ask"; in a non-interactive
|
||||
#' session, "default" falls back to "all". With "ask", this function will
|
||||
#' prompt the user to select which template items will be added to the new app
|
||||
@@ -79,15 +76,19 @@ shinyAppTemplate <- function(path = NULL, examples = "default", dryrun = FALSE)
|
||||
# =======================================================
|
||||
|
||||
choices <- c(
|
||||
app = "app.R : Main application file",
|
||||
rdir = "R/example.R : Helper file with R code",
|
||||
module = "R/example-module.R : Example module",
|
||||
shinytest = "tests/shinytest/ : Tests using the shinytest package",
|
||||
testthat = "tests/testthat/ : Tests using the testthat package"
|
||||
app = "app.R : Main application file",
|
||||
rdir = "R/example.R : Helper file with R code",
|
||||
module = "R/example-module.R : Example module",
|
||||
tests = "tests/testthat/ : Tests using {testthat} and {shinytest2}"
|
||||
)
|
||||
|
||||
# Support legacy value
|
||||
examples[examples == "shinytest"] <- "tests"
|
||||
examples[examples == "testthat"] <- "tests"
|
||||
examples <- unique(examples)
|
||||
|
||||
if (identical(examples, "default")) {
|
||||
if (interactive()) {
|
||||
if (rlang::is_interactive()) {
|
||||
examples <- "ask"
|
||||
} else {
|
||||
examples <- "all"
|
||||
@@ -124,18 +125,8 @@ shinyAppTemplate <- function(path = NULL, examples = "default", dryrun = FALSE)
|
||||
return(invisible())
|
||||
}
|
||||
|
||||
if ("shinytest" %in% examples) {
|
||||
if (!is_installed("shinytest", "1.4.0"))
|
||||
{
|
||||
message(
|
||||
"The tests/shinytest directory needs shinytest 1.4.0 or later to work properly."
|
||||
)
|
||||
if (is_installed("shinytest")) {
|
||||
message("You currently have shinytest ",
|
||||
get_package_version("shinytest"), " installed.")
|
||||
}
|
||||
|
||||
}
|
||||
if ("tests" %in% examples) {
|
||||
rlang::check_installed("shinytest2", "for {testthat} tests to work as expected")
|
||||
}
|
||||
|
||||
# =======================================================
|
||||
@@ -208,16 +199,13 @@ shinyAppTemplate <- function(path = NULL, examples = "default", dryrun = FALSE)
|
||||
}
|
||||
|
||||
# Copy the files for a tests/ subdirectory
|
||||
copy_test_dir <- function(name) {
|
||||
copy_test_dir <- function() {
|
||||
files <- dir(template_path("tests"), recursive = TRUE)
|
||||
# Note: This is not the same as using dir(pattern = "^shinytest"), since
|
||||
# that will not match files inside of shinytest/.
|
||||
files <- files[grepl(paste0("^", name), files)]
|
||||
|
||||
# Filter out files that are not module files in the R directory.
|
||||
if (! "rdir" %in% examples) {
|
||||
# find all files in the testthat folder that are not module or server files
|
||||
is_r_folder_file <- (!grepl("module|server", basename(files))) & (dirname(files) == "testthat")
|
||||
is_r_folder_file <- !grepl("module|server|shinytest2|testthat", basename(files))
|
||||
files <- files[!is_r_folder_file]
|
||||
}
|
||||
|
||||
@@ -282,12 +270,10 @@ shinyAppTemplate <- function(path = NULL, examples = "default", dryrun = FALSE)
|
||||
copy_file(file.path("R", module_files))
|
||||
}
|
||||
|
||||
# tests/ dir
|
||||
if ("shinytest" %in% examples) {
|
||||
copy_test_dir("shinytest")
|
||||
}
|
||||
if ("testthat" %in% examples) {
|
||||
copy_test_dir("testthat")
|
||||
# tests/testthat dir
|
||||
if ("tests" %in% examples) {
|
||||
copy_test_dir()
|
||||
}
|
||||
|
||||
invisible()
|
||||
}
|
||||
|
||||
@@ -321,34 +321,38 @@ RestoreContext <- R6Class("RestoreContext",
|
||||
if (substr(queryString, 1, 1) == '?')
|
||||
queryString <- substr(queryString, 2, nchar(queryString))
|
||||
|
||||
# The "=" after "_inputs_" is optional. Shiny doesn't generate URLs with
|
||||
# "=", but httr always adds "=".
|
||||
inputs_reg <- "(^|&)_inputs_=?(&|$)"
|
||||
values_reg <- "(^|&)_values_=?(&|$)"
|
||||
|
||||
# Error if multiple '_inputs_' or '_values_'. This is needed because
|
||||
# strsplit won't add an entry if the search pattern is at the end of a
|
||||
# string.
|
||||
if (length(gregexpr("(^|&)_inputs_(&|$)", queryString)[[1]]) > 1)
|
||||
if (length(gregexpr(inputs_reg, queryString)[[1]]) > 1)
|
||||
stop("Invalid state string: more than one '_inputs_' found")
|
||||
if (length(gregexpr("(^|&)_values_(&|$)", queryString)[[1]]) > 1)
|
||||
if (length(gregexpr(values_reg, queryString)[[1]]) > 1)
|
||||
stop("Invalid state string: more than one '_values_' found")
|
||||
|
||||
# Look for _inputs_ and store following content in inputStr
|
||||
splitStr <- strsplit(queryString, "(^|&)_inputs_(&|$)")[[1]]
|
||||
splitStr <- strsplit(queryString, inputs_reg)[[1]]
|
||||
if (length(splitStr) == 2) {
|
||||
inputStr <- splitStr[2]
|
||||
# Remove any _values_ (and content after _values_) that may come after
|
||||
# _inputs_
|
||||
inputStr <- strsplit(inputStr, "(^|&)_values_(&|$)")[[1]][1]
|
||||
inputStr <- strsplit(inputStr, values_reg)[[1]][1]
|
||||
|
||||
} else {
|
||||
inputStr <- ""
|
||||
}
|
||||
|
||||
# Look for _values_ and store following content in valueStr
|
||||
splitStr <- strsplit(queryString, "(^|&)_values_(&|$)")[[1]]
|
||||
splitStr <- strsplit(queryString, values_reg)[[1]]
|
||||
if (length(splitStr) == 2) {
|
||||
valueStr <- splitStr[2]
|
||||
# Remove any _inputs_ (and content after _inputs_) that may come after
|
||||
# _values_
|
||||
valueStr <- strsplit(valueStr, "(^|&)_inputs_(&|$)")[[1]][1]
|
||||
valueStr <- strsplit(valueStr, inputs_reg)[[1]][1]
|
||||
|
||||
} else {
|
||||
valueStr <- ""
|
||||
@@ -359,16 +363,20 @@ RestoreContext <- R6Class("RestoreContext",
|
||||
values <- parseQueryString(valueStr, nested = TRUE)
|
||||
|
||||
valuesFromJSON <- function(vals) {
|
||||
mapply(names(vals), vals, SIMPLIFY = FALSE,
|
||||
varsUnparsed <- c()
|
||||
valsParsed <- mapply(names(vals), vals, SIMPLIFY = FALSE,
|
||||
FUN = function(name, value) {
|
||||
tryCatch(
|
||||
safeFromJSON(value),
|
||||
error = function(e) {
|
||||
stop("Failed to parse URL parameter \"", name, "\"")
|
||||
varsUnparsed <<- c(varsUnparsed, name)
|
||||
message("Failed to parse URL parameter \"", name, "\"")
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
valsParsed[varsUnparsed] <- NULL
|
||||
valsParsed
|
||||
}
|
||||
|
||||
inputs <- valuesFromJSON(inputs)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#' @param sidebarPanel The [sidebarPanel] containing input controls
|
||||
#' @param mainPanel The [mainPanel] containing outputs
|
||||
#' @keywords internal
|
||||
#' @return A UI defintion that can be passed to the [shinyUI] function
|
||||
#' @return A UI definition that can be passed to the [shinyUI] function
|
||||
#' @export
|
||||
pageWithSidebar <- function(headerPanel,
|
||||
sidebarPanel,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#' Can also be set as a side effect of the [titlePanel()] function.
|
||||
#' @inheritParams bootstrapPage
|
||||
#'
|
||||
#' @return A UI defintion that can be passed to the [shinyUI] function.
|
||||
#' @return A UI definition that can be passed to the [shinyUI] function.
|
||||
#'
|
||||
#' @details To create a fluid page use the `fluidPage` function and include
|
||||
#' instances of `fluidRow` and [column()] within it. As an
|
||||
@@ -111,7 +111,7 @@ fluidRow <- function(...) {
|
||||
#' @param title The browser window title (defaults to the host URL of the page)
|
||||
#' @inheritParams bootstrapPage
|
||||
#'
|
||||
#' @return A UI defintion that can be passed to the [shinyUI] function.
|
||||
#' @return A UI definition that can be passed to the [shinyUI] function.
|
||||
#'
|
||||
#' @details To create a fixed page use the `fixedPage` function and include
|
||||
#' instances of `fixedRow` and [column()] within it. Note that
|
||||
@@ -516,7 +516,7 @@ splitLayout <- function(..., cellWidths = NULL, cellArgs = list()) {
|
||||
children <- children[childIdx]
|
||||
count <- length(children)
|
||||
|
||||
if (length(cellWidths) == 0 || is.na(cellWidths)) {
|
||||
if (length(cellWidths) == 0 || isTRUE(is.na(cellWidths))) {
|
||||
cellWidths <- sprintf("%.3f%%", 100 / count)
|
||||
}
|
||||
cellWidths <- rep(cellWidths, length.out = count)
|
||||
|
||||
@@ -24,7 +24,7 @@ NULL
|
||||
#' This will be used as the lang in the \code{<html>} tag, as in \code{<html lang="en">}.
|
||||
#' The default (NULL) results in an empty string.
|
||||
#'
|
||||
#' @return A UI defintion that can be passed to the [shinyUI] function.
|
||||
#' @return A UI definition that can be passed to the [shinyUI] function.
|
||||
#'
|
||||
#' @note The `basicPage` function is deprecated, you should use the
|
||||
#' [fluidPage()] function instead.
|
||||
@@ -385,7 +385,7 @@ collapseSizes <- function(padding) {
|
||||
#' @inheritParams bootstrapPage
|
||||
#' @param icon Optional icon to appear on a `navbarMenu` tab.
|
||||
#'
|
||||
#' @return A UI defintion that can be passed to the [shinyUI] function.
|
||||
#' @return A UI definition that can be passed to the [shinyUI] function.
|
||||
#'
|
||||
#' @details The `navbarMenu` function can be used to create an embedded
|
||||
#' menu within the navbar that in turns includes additional tabPanels (see
|
||||
|
||||
@@ -23,7 +23,18 @@
|
||||
#' @param buttonLabel The label used on the button. Can be text or an HTML tag
|
||||
#' object.
|
||||
#' @param placeholder The text to show before a file has been uploaded.
|
||||
#' @param capture What source to use for capturing image, audio or video data.
|
||||
#' This attribute facilitates user access to a device's media capture
|
||||
#' mechanism, such as a camera, or microphone, from within a file upload
|
||||
#' control.
|
||||
#'
|
||||
#' A value of `user` indicates that the user-facing camera and/or microphone
|
||||
#' should be used. A value of `environment` specifies that the outward-facing
|
||||
#' camera and/or microphone should be used.
|
||||
#'
|
||||
#' By default on most phones, this will accept still photos or video. For
|
||||
#' still photos only, also use `accept="image/*"`. For video only, use
|
||||
#' `accept="video/*"`.
|
||||
#' @examples
|
||||
#' ## Only run examples in interactive R sessions
|
||||
#' if (interactive()) {
|
||||
@@ -73,7 +84,8 @@
|
||||
#'
|
||||
#' @export
|
||||
fileInput <- function(inputId, label, multiple = FALSE, accept = NULL,
|
||||
width = NULL, buttonLabel = "Browse...", placeholder = "No file selected") {
|
||||
width = NULL, buttonLabel = "Browse...", placeholder = "No file selected",
|
||||
capture = NULL) {
|
||||
|
||||
restoredValue <- restoreInput(id = inputId, default = NULL)
|
||||
|
||||
@@ -101,6 +113,9 @@ fileInput <- function(inputId, label, multiple = FALSE, accept = NULL,
|
||||
if (length(accept) > 0)
|
||||
inputTag$attribs$accept <- paste(accept, collapse=',')
|
||||
|
||||
if (!is.null(capture)) {
|
||||
inputTag$attribs$capture <- capture
|
||||
}
|
||||
|
||||
div(class = "form-group shiny-input-container",
|
||||
style = css(width = validateCssUnit(width)),
|
||||
|
||||
@@ -121,7 +121,8 @@ runGist <- function(gist, destdir = NULL, ...) {
|
||||
#' @param username GitHub username. If `repo` is of the form
|
||||
#' `"username/repo"`, `username` will be taken from `repo`.
|
||||
#' @param ref Desired git reference. Could be a commit, tag, or branch name.
|
||||
#' Defaults to `"master"`.
|
||||
#' Defaults to `"HEAD"`, which means the default branch on GitHub, typically
|
||||
#' `"main"` or `"master"`.
|
||||
#' @export
|
||||
#' @examples
|
||||
#' ## Only run this example in interactive R sessions
|
||||
@@ -133,7 +134,7 @@ runGist <- function(gist, destdir = NULL, ...) {
|
||||
#' runGitHub("shiny_example", "rstudio", subdir = "inst/shinyapp/")
|
||||
#' }
|
||||
runGitHub <- function(repo, username = getOption("github.user"),
|
||||
ref = "master", subdir = NULL, destdir = NULL, ...) {
|
||||
ref = "HEAD", subdir = NULL, destdir = NULL, ...) {
|
||||
|
||||
if (grepl('/', repo)) {
|
||||
res <- strsplit(repo, '/')[[1]]
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#' ports will be tried.
|
||||
#' @param launch.browser If true, the system's default web browser will be
|
||||
#' launched automatically after the app is started. Defaults to true in
|
||||
#' interactive sessions only. This value of this parameter can also be a
|
||||
#' interactive sessions only. The value of this parameter can also be a
|
||||
#' function to call with the application's URL.
|
||||
#' @param host The IPv4 address that the application should listen on. Defaults
|
||||
#' to the `shiny.host` option, if set, or `"127.0.0.1"` if not. See
|
||||
|
||||
@@ -94,6 +94,10 @@ getShinyOption <- function(name, default = NULL) {
|
||||
#' numbers to JSON format to send to the client web browser.}
|
||||
#' \item{shiny.launch.browser (defaults to `interactive()`)}{A boolean which controls the default behavior
|
||||
#' when an app is run. See [runApp()] for more information.}
|
||||
#' \item{shiny.mathjax.url (defaults to `"https://mathjax.rstudio.com/latest/MathJax.js"`)}{
|
||||
#' The URL that should be used to load MathJax, via [withMathJax()].}
|
||||
#' \item{shiny.mathjax.config (defaults to `"config=TeX-AMS-MML_HTMLorMML"`)}{The querystring
|
||||
#' used to load MathJax, via [withMathJax()].}
|
||||
#' \item{shiny.maxRequestSize (defaults to 5MB)}{This is a number which specifies the maximum
|
||||
#' web request size, which serves as a size limit for file uploads.}
|
||||
#' \item{shiny.minified (defaults to `TRUE`)}{By default
|
||||
@@ -125,6 +129,9 @@ getShinyOption <- function(name, default = NULL) {
|
||||
#' console.}
|
||||
#' \item{shiny.testmode (defaults to `FALSE`)}{If `TRUE`, then various features for testing Shiny
|
||||
#' applications are enabled.}
|
||||
#' \item{shiny.snapshotsortc (defaults to `FALSE`)}{If `TRUE`, test snapshot keys
|
||||
#' for \pkg{shinytest} will be sorted consistently using the C locale. Snapshots
|
||||
#' retrieved by \pkg{shinytest2} will always sort using the C locale.}
|
||||
#' \item{shiny.trace (defaults to `FALSE`)}{Print messages sent between the R server and the web
|
||||
#' browser client to the R console. This is useful for debugging. Possible
|
||||
#' values are `"send"` (only print messages sent to the client),
|
||||
|
||||
38
R/shiny.R
38
R/shiny.R
@@ -478,6 +478,35 @@ ShinySession <- R6Class(
|
||||
# "json" unless requested otherwise. The only other valid value is
|
||||
# "rds".
|
||||
format <- params$format %||% "json"
|
||||
# Machines can test their snapshot under different locales.
|
||||
# R CMD check runs under the `C` locale.
|
||||
# However, before this parameter, existing snapshots were most likely not
|
||||
# under the `C` locale is would cause failures. This parameter allows
|
||||
# users to opt-in to the `C` locale.
|
||||
# From ?sort:
|
||||
# However, there are some caveats with the radix sort:
|
||||
# If ‘x’ is a ‘character’ vector, all elements must share the
|
||||
# same encoding. Only UTF-8 (including ASCII) and Latin-1
|
||||
# encodings are supported. Collation always follows the "C"
|
||||
# locale.
|
||||
# {shinytest2} will always set `sortC=1`
|
||||
# {shinytest} does not have `sortC` functionality.
|
||||
# Users should set `options(shiny.snapshotsortc = TRUE)` within their app.
|
||||
# The sortingMethod should always be `radix` going forward.
|
||||
sortMethod <-
|
||||
if (!is.null(params$sortC)) {
|
||||
if (params$sortC != "1") {
|
||||
stop("The `sortC` parameter can only be `1` or not supplied")
|
||||
}
|
||||
"radix"
|
||||
} else {
|
||||
# Allow users to set an option for {shinytest2}.
|
||||
if (isTRUE(getShinyOption("snapshotsortc", default = FALSE))) {
|
||||
"radix"
|
||||
} else {
|
||||
"auto"
|
||||
}
|
||||
}
|
||||
|
||||
values <- list()
|
||||
|
||||
@@ -520,7 +549,7 @@ ShinySession <- R6Class(
|
||||
}
|
||||
)
|
||||
|
||||
values$input <- sortByName(values$input)
|
||||
values$input <- sortByName(values$input, method = sortMethod)
|
||||
}
|
||||
|
||||
if (!is.null(params$output)) {
|
||||
@@ -548,7 +577,7 @@ ShinySession <- R6Class(
|
||||
}
|
||||
)
|
||||
|
||||
values$output <- sortByName(values$output)
|
||||
values$output <- sortByName(values$output, method = sortMethod)
|
||||
}
|
||||
|
||||
if (!is.null(params$export)) {
|
||||
@@ -569,7 +598,7 @@ ShinySession <- R6Class(
|
||||
)
|
||||
}
|
||||
|
||||
values$export <- sortByName(values$export)
|
||||
values$export <- sortByName(values$export, method = sortMethod)
|
||||
}
|
||||
|
||||
# Make sure input, output, and export are all named lists (at this
|
||||
@@ -1719,7 +1748,7 @@ ShinySession <- R6Class(
|
||||
},
|
||||
|
||||
getTestSnapshotUrl = function(input = TRUE, output = TRUE, export = TRUE,
|
||||
format = "json") {
|
||||
format = "json", sortC = FALSE) {
|
||||
reqString <- function(group, value) {
|
||||
if (isTRUE(value))
|
||||
paste0(group, "=1")
|
||||
@@ -1733,6 +1762,7 @@ ShinySession <- R6Class(
|
||||
reqString("input", input),
|
||||
reqString("output", output),
|
||||
reqString("export", export),
|
||||
reqString("sortC", sortC),
|
||||
paste0("format=", format),
|
||||
sep = "&"
|
||||
)
|
||||
|
||||
@@ -286,7 +286,7 @@ shinyAppDir_serverR <- function(appDir, options=list()) {
|
||||
#
|
||||
# The return value is a function that halts monitoring when called.
|
||||
initAutoReloadMonitor <- function(dir) {
|
||||
if (!getOption("shiny.autoreload", FALSE)) {
|
||||
if (!get_devmode_option("shiny.autoreload", FALSE)) {
|
||||
return(function(){})
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ initAutoReloadMonitor <- function(dir) {
|
||||
#' @param appDir The application directory. If `appDir` is `NULL` or
|
||||
#' not supplied, the nearest enclosing directory that is a Shiny app, starting
|
||||
#' with the current directory, is used.
|
||||
#' @param renv The environmeny in which the files in the `R/` directory should
|
||||
#' @param renv The environment in which the files in the `R/` directory should
|
||||
#' be evaluated.
|
||||
#' @param globalrenv The environment in which `global.R` should be evaluated. If
|
||||
#' `NULL`, `global.R` will not be evaluated at all.
|
||||
|
||||
@@ -14,7 +14,11 @@ NULL
|
||||
#' # now we can just write "static" content without withMathJax()
|
||||
#' div("more math here $$\\sqrt{2}$$")
|
||||
withMathJax <- function(...) {
|
||||
path <- 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
|
||||
path <- paste0(
|
||||
getOption("shiny.mathjax.url", "https://mathjax.rstudio.com/latest/MathJax.js"),
|
||||
"?",
|
||||
getOption("shiny.mathjax.config", "config=TeX-AMS-MML_HTMLorMML")
|
||||
)
|
||||
tagList(
|
||||
tags$head(
|
||||
singleton(tags$script(src = path, type = 'text/javascript'))
|
||||
|
||||
@@ -778,9 +778,9 @@ renderUI <- function(expr, env = parent.frame(), quoted = FALSE,
|
||||
#' function.)
|
||||
#' @param contentType A string of the download's
|
||||
#' [content type](https://en.wikipedia.org/wiki/Internet_media_type), for
|
||||
#' example `"text/csv"` or `"image/png"`. If `NULL` or
|
||||
#' `NA`, the content type will be guessed based on the filename
|
||||
#' extension, or `application/octet-stream` if the extension is unknown.
|
||||
#' example `"text/csv"` or `"image/png"`. If `NULL`, the content type
|
||||
#' will be guessed based on the filename extension, or
|
||||
#' `application/octet-stream` if the extension is unknown.
|
||||
#' @param outputArgs A list of arguments to be passed through to the implicit
|
||||
#' call to [downloadButton()] when `downloadHandler` is used
|
||||
#' in an interactive R Markdown document.
|
||||
@@ -810,7 +810,7 @@ renderUI <- function(expr, env = parent.frame(), quoted = FALSE,
|
||||
#' shinyApp(ui, server)
|
||||
#' }
|
||||
#' @export
|
||||
downloadHandler <- function(filename, content, contentType=NA, outputArgs=list()) {
|
||||
downloadHandler <- function(filename, content, contentType=NULL, outputArgs=list()) {
|
||||
renderFunc <- function(shinysession, name, ...) {
|
||||
shinysession$registerDownload(name, filename, contentType, content)
|
||||
}
|
||||
|
||||
16
R/utils.R
16
R/utils.R
@@ -162,7 +162,7 @@ mergeVectors <- function(a, b) {
|
||||
# Sort a vector by the names of items. If there are multiple items with the
|
||||
# same name, preserve the original order of those items. For empty
|
||||
# vectors/lists/NULL, return the original value.
|
||||
sortByName <- function(x) {
|
||||
sortByName <- function(x, method = "auto") {
|
||||
if (any_unnamed(x))
|
||||
stop("All items must be named")
|
||||
|
||||
@@ -170,7 +170,19 @@ sortByName <- function(x) {
|
||||
if (length(x) == 0)
|
||||
return(x)
|
||||
|
||||
x[order(names(x))]
|
||||
# Must provide consistent sort order
|
||||
# https://github.com/rstudio/shinytest/issues/409
|
||||
# Using a flag in the snapshot url to determine the method
|
||||
# `method="radix"` uses `C` locale, which is consistent across platforms
|
||||
# Even if two platforms share `en_us.UTF-8`, they may not sort consistently
|
||||
# https://blog.zhimingwang.org/macos-lc_collate-hunt
|
||||
# (macOS) $ LC_ALL=en_US.UTF-8 sort <<<$'python-dev\npython3-dev'
|
||||
# python-dev
|
||||
# python3-dev
|
||||
# (Linux) $ LC_ALL=en_US.UTF-8 sort <<<$'python-dev\npython3-dev'
|
||||
# python3-dev
|
||||
# python-dev
|
||||
x[order(names(x), method = method)]
|
||||
}
|
||||
|
||||
# Sort a vector. If a character vector, sort using C locale, which is consistent
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
library(shinytest)
|
||||
expect_pass(testApp("../", suffix = osName()))
|
||||
@@ -1,12 +0,0 @@
|
||||
app <- ShinyDriver$new("../../")
|
||||
app$snapshotInit("mytest")
|
||||
|
||||
app$snapshot()
|
||||
{{
|
||||
if (isTRUE(module)) {
|
||||
'
|
||||
app$setInputs(`examplemodule1-button` = "click")
|
||||
app$setInputs(`examplemodule1-button` = "click")
|
||||
app$snapshot()'
|
||||
}
|
||||
}}
|
||||
@@ -1,9 +1 @@
|
||||
library(testthat)
|
||||
|
||||
test_dir(
|
||||
"./testthat",
|
||||
# Run in the app's environment containing all support methods.
|
||||
env = shiny::loadSupport(),
|
||||
# Display the regular progress output and throw an error if any test error is found
|
||||
reporter = c("progress", "fail")
|
||||
)
|
||||
shinytest2::test_app()
|
||||
|
||||
@@ -14,5 +14,4 @@ if (isTRUE(rdir)) {
|
||||
expect_equal(output$sequence, "1 2 3 4 5 6 7 8 9 10 11 12")
|
||||
'
|
||||
}
|
||||
}}
|
||||
})
|
||||
}}})
|
||||
|
||||
18
inst/app_template/tests/testthat/test-shinytest2.R
Normal file
18
inst/app_template/tests/testthat/test-shinytest2.R
Normal file
@@ -0,0 +1,18 @@
|
||||
library(shinytest2)
|
||||
|
||||
test_that("Initial snapshot values are consistent", {
|
||||
app <- AppDriver$new(name = "init")
|
||||
app$expect_values()
|
||||
}){{
|
||||
if (isTRUE(module)) {
|
||||
HTML('
|
||||
|
||||
|
||||
test_that("Module values are consistent", {
|
||||
app <- AppDriver$new(name = "mod")
|
||||
app$click("examplemodule1-button")
|
||||
app$click("examplemodule1-button")
|
||||
app$expect_values()
|
||||
})')
|
||||
}
|
||||
}}
|
||||
File diff suppressed because one or more lines are too long
7
inst/www/shared/shiny-autoreload.js.map
Normal file
7
inst/www/shared/shiny-autoreload.js.map
Normal file
File diff suppressed because one or more lines are too long
@@ -1,2 +1,2 @@
|
||||
/*! shiny 1.7.1.9002 | (c) 2012-2022 RStudio, PBC. | License: GPL-3 | file LICENSE */
|
||||
/*! shiny 1.7.1.9003 | (c) 2012-2022 RStudio, PBC. | License: GPL-3 | file LICENSE */
|
||||
#showcase-well{border-radius:0}.shiny-code{background-color:#fff;margin-bottom:0}.shiny-code code{font-family:Menlo,Consolas,"Courier New",monospace}.shiny-code-container{margin-top:20px;clear:both}.shiny-code-container h3{display:inline;margin-right:15px}.showcase-header{font-size:16px;font-weight:normal}.showcase-code-link{text-align:right;padding:15px}#showcase-app-container{vertical-align:top}#showcase-code-tabs{margin-right:15px}#showcase-code-tabs pre{border:none;line-height:1em}#showcase-code-tabs .nav{margin-bottom:0}#showcase-code-tabs ul{margin-bottom:0}#showcase-code-tabs .tab-content{border-style:solid;border-color:#e5e5e5;border-width:0px 1px 1px 1px;overflow:auto;border-bottom-right-radius:4px;border-bottom-left-radius:4px}#showcase-app-code{width:100%}#showcase-code-position-toggle{float:right}#showcase-sxs-code{padding-top:20px;vertical-align:top}.showcase-code-license{display:block;text-align:right}#showcase-code-content pre{background-color:#fff}
|
||||
|
||||
File diff suppressed because one or more lines are too long
7
inst/www/shared/shiny-showcase.js.map
Normal file
7
inst/www/shared/shiny-showcase.js.map
Normal file
File diff suppressed because one or more lines are too long
@@ -1,3 +1,3 @@
|
||||
/*! shiny 1.7.1.9002 | (c) 2012-2022 RStudio, PBC. | License: GPL-3 | file LICENSE */
|
||||
/*! shiny 1.7.1.9003 | (c) 2012-2022 RStudio, PBC. | License: GPL-3 | file LICENSE */
|
||||
(function(){var a=eval;window.addEventListener("message",function(i){var e=i.data;e.code&&a(e.code)});})();
|
||||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vc3JjdHMvc3JjL3V0aWxzL2V2YWwudHMiLCAiLi4vLi4vLi4vc3JjdHMvZXh0cmFzL3NoaW55LXRlc3Rtb2RlLnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyIvL2VzYnVpbGQuZ2l0aHViLmlvL2NvbnRlbnQtdHlwZXMvI2RpcmVjdC1ldmFsXG4vL3RsL2RyO1xuLy8gKiBEaXJlY3QgdXNhZ2Ugb2YgYGV2YWwoXCJ4XCIpYCBpcyBiYWQgd2l0aCBidW5kbGVkIGNvZGUuXG4vLyAqIEluc3RlYWQsIHVzZSBpbmRpcmVjdCBjYWxscyB0byBgZXZhbGAgc3VjaCBhcyBgaW5kaXJlY3RFdmFsKFwieFwiKWBcbi8vICAgKiBFdmVuIGp1c3QgcmVuYW1pbmcgdGhlIGZ1bmN0aW9uIHdvcmtzIHdlbGwgZW5vdWdoLlxuLy8gPiBUaGlzIGlzIGtub3duIGFzIFwiaW5kaXJlY3QgZXZhbFwiIGJlY2F1c2UgZXZhbCBpcyBub3QgYmVpbmcgY2FsbGVkIGRpcmVjdGx5LCBhbmQgc28gZG9lcyBub3QgdHJpZ2dlciB0aGUgZ3JhbW1hdGljYWwgc3BlY2lhbCBjYXNlIGZvciBkaXJlY3QgZXZhbCBpbiB0aGUgSmF2YVNjcmlwdCBWTS4gWW91IGNhbiBjYWxsIGluZGlyZWN0IGV2YWwgdXNpbmcgYW55IHN5bnRheCBhdCBhbGwgZXhjZXB0IGZvciBhbiBleHByZXNzaW9uIG9mIHRoZSBleGFjdCBmb3JtIGV2YWwoJ3gnKS4gRm9yIGV4YW1wbGUsIHZhciBldmFsMiA9IGV2YWw7IGV2YWwyKCd4JykgYW5kIFtldmFsXVswXSgneCcpIGFuZCB3aW5kb3cuZXZhbCgneCcpIGFyZSBhbGwgaW5kaXJlY3QgZXZhbCBjYWxscy5cbi8vID4gV2hlbiB5b3UgdXNlIGluZGlyZWN0IGV2YWwsIHRoZSBjb2RlIGlzIGV2YWx1YXRlZCBpbiB0aGUgZ2xvYmFsIHNjb3BlIGluc3RlYWQgb2YgaW4gdGhlIGlubGluZSBzY29wZSBvZiB0aGUgY2FsbGVyLlxudmFyIGluZGlyZWN0RXZhbCA9IGV2YWw7XG5leHBvcnQgeyBpbmRpcmVjdEV2YWwgfTsiLCAiLyogZXNsaW50LWRpc2FibGUgdW5pY29ybi9maWxlbmFtZS1jYXNlICovXG5pbXBvcnQgeyBpbmRpcmVjdEV2YWwgfSBmcm9tIFwiLi4vc3JjL3V0aWxzL2V2YWxcIjsgLy8gTGlzdGVuIGZvciBtZXNzYWdlcyBmcm9tIHBhcmVudCBmcmFtZS4gVGhpcyBmaWxlIGlzIG9ubHkgYWRkZWQgd2hlbiB0aGVcbi8vIHNoaW55LnRlc3Rtb2RlIG9wdGlvbiBpcyBUUlVFLlxuXG53aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcihcIm1lc3NhZ2VcIiwgZnVuY3Rpb24gKGUpIHtcbiAgdmFyIG1lc3NhZ2UgPSBlLmRhdGE7XG4gIGlmIChtZXNzYWdlLmNvZGUpIGluZGlyZWN0RXZhbChtZXNzYWdlLmNvZGUpO1xufSk7Il0sCiAgIm1hcHBpbmdzIjogIjtZQU9BLEdBQUksR0FBZSxLQ0huQixPQUFPLGlCQUFpQixVQUFXLFNBQVUsRUFBRyxDQUM5QyxHQUFJLEdBQVUsRUFBRSxLQUNoQixBQUFJLEVBQVEsTUFBTSxFQUFhLEVBQVEiLAogICJuYW1lcyI6IFtdCn0K
|
||||
//# sourceMappingURL=shiny-testmode.js.map
|
||||
|
||||
7
inst/www/shared/shiny-testmode.js.map
Normal file
7
inst/www/shared/shiny-testmode.js.map
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": ["../../../srcts/src/utils/eval.ts", "../../../srcts/extras/shiny-testmode.ts"],
|
||||
"sourcesContent": ["//esbuild.github.io/content-types/#direct-eval\n//tl/dr;\n// * Direct usage of `eval(\"x\")` is bad with bundled code.\n// * Instead, use indirect calls to `eval` such as `indirectEval(\"x\")`\n// * Even just renaming the function works well enough.\n// > This is known as \"indirect eval\" because eval is not being called directly, and so does not trigger the grammatical special case for direct eval in the JavaScript VM. You can call indirect eval using any syntax at all except for an expression of the exact form eval('x'). For example, var eval2 = eval; eval2('x') and [eval][0]('x') and window.eval('x') are all indirect eval calls.\n// > When you use indirect eval, the code is evaluated in the global scope instead of in the inline scope of the caller.\nvar indirectEval = eval;\nexport { indirectEval };", "/* eslint-disable unicorn/filename-case */\nimport { indirectEval } from \"../src/utils/eval\"; // Listen for messages from parent frame. This file is only added when the\n// shiny.testmode option is TRUE.\n\nwindow.addEventListener(\"message\", function (e) {\n var message = e.data;\n if (message.code) indirectEval(message.code);\n});"],
|
||||
"mappings": ";YAOA,GAAI,GAAe,KCHnB,OAAO,iBAAiB,UAAW,SAAU,EAAG,CAC9C,GAAI,GAAU,EAAE,KAChB,AAAI,EAAQ,MAAM,EAAa,EAAQ",
|
||||
"names": []
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
2
inst/www/shared/shiny.min.css
vendored
2
inst/www/shared/shiny.min.css
vendored
File diff suppressed because one or more lines are too long
4
inst/www/shared/shiny.min.js
vendored
4
inst/www/shared/shiny.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -85,40 +85,40 @@ user. Always \code{NULL} for a \code{MockShinySesion}.}
|
||||
\section{Methods}{
|
||||
\subsection{Public methods}{
|
||||
\itemize{
|
||||
\item \href{#method-new}{\code{MockShinySession$new()}}
|
||||
\item \href{#method-onFlush}{\code{MockShinySession$onFlush()}}
|
||||
\item \href{#method-onFlushed}{\code{MockShinySession$onFlushed()}}
|
||||
\item \href{#method-onEnded}{\code{MockShinySession$onEnded()}}
|
||||
\item \href{#method-isEnded}{\code{MockShinySession$isEnded()}}
|
||||
\item \href{#method-isClosed}{\code{MockShinySession$isClosed()}}
|
||||
\item \href{#method-close}{\code{MockShinySession$close()}}
|
||||
\item \href{#method-cycleStartAction}{\code{MockShinySession$cycleStartAction()}}
|
||||
\item \href{#method-fileUrl}{\code{MockShinySession$fileUrl()}}
|
||||
\item \href{#method-setInputs}{\code{MockShinySession$setInputs()}}
|
||||
\item \href{#method-.scheduleTask}{\code{MockShinySession$.scheduleTask()}}
|
||||
\item \href{#method-elapse}{\code{MockShinySession$elapse()}}
|
||||
\item \href{#method-.now}{\code{MockShinySession$.now()}}
|
||||
\item \href{#method-defineOutput}{\code{MockShinySession$defineOutput()}}
|
||||
\item \href{#method-getOutput}{\code{MockShinySession$getOutput()}}
|
||||
\item \href{#method-ns}{\code{MockShinySession$ns()}}
|
||||
\item \href{#method-flushReact}{\code{MockShinySession$flushReact()}}
|
||||
\item \href{#method-makeScope}{\code{MockShinySession$makeScope()}}
|
||||
\item \href{#method-setEnv}{\code{MockShinySession$setEnv()}}
|
||||
\item \href{#method-setReturned}{\code{MockShinySession$setReturned()}}
|
||||
\item \href{#method-getReturned}{\code{MockShinySession$getReturned()}}
|
||||
\item \href{#method-genId}{\code{MockShinySession$genId()}}
|
||||
\item \href{#method-rootScope}{\code{MockShinySession$rootScope()}}
|
||||
\item \href{#method-unhandledError}{\code{MockShinySession$unhandledError()}}
|
||||
\item \href{#method-freezeValue}{\code{MockShinySession$freezeValue()}}
|
||||
\item \href{#method-onSessionEnded}{\code{MockShinySession$onSessionEnded()}}
|
||||
\item \href{#method-registerDownload}{\code{MockShinySession$registerDownload()}}
|
||||
\item \href{#method-getCurrentOutputInfo}{\code{MockShinySession$getCurrentOutputInfo()}}
|
||||
\item \href{#method-clone}{\code{MockShinySession$clone()}}
|
||||
\item \href{#method-MockShinySession-new}{\code{MockShinySession$new()}}
|
||||
\item \href{#method-MockShinySession-onFlush}{\code{MockShinySession$onFlush()}}
|
||||
\item \href{#method-MockShinySession-onFlushed}{\code{MockShinySession$onFlushed()}}
|
||||
\item \href{#method-MockShinySession-onEnded}{\code{MockShinySession$onEnded()}}
|
||||
\item \href{#method-MockShinySession-isEnded}{\code{MockShinySession$isEnded()}}
|
||||
\item \href{#method-MockShinySession-isClosed}{\code{MockShinySession$isClosed()}}
|
||||
\item \href{#method-MockShinySession-close}{\code{MockShinySession$close()}}
|
||||
\item \href{#method-MockShinySession-cycleStartAction}{\code{MockShinySession$cycleStartAction()}}
|
||||
\item \href{#method-MockShinySession-fileUrl}{\code{MockShinySession$fileUrl()}}
|
||||
\item \href{#method-MockShinySession-setInputs}{\code{MockShinySession$setInputs()}}
|
||||
\item \href{#method-MockShinySession-.scheduleTask}{\code{MockShinySession$.scheduleTask()}}
|
||||
\item \href{#method-MockShinySession-elapse}{\code{MockShinySession$elapse()}}
|
||||
\item \href{#method-MockShinySession-.now}{\code{MockShinySession$.now()}}
|
||||
\item \href{#method-MockShinySession-defineOutput}{\code{MockShinySession$defineOutput()}}
|
||||
\item \href{#method-MockShinySession-getOutput}{\code{MockShinySession$getOutput()}}
|
||||
\item \href{#method-MockShinySession-ns}{\code{MockShinySession$ns()}}
|
||||
\item \href{#method-MockShinySession-flushReact}{\code{MockShinySession$flushReact()}}
|
||||
\item \href{#method-MockShinySession-makeScope}{\code{MockShinySession$makeScope()}}
|
||||
\item \href{#method-MockShinySession-setEnv}{\code{MockShinySession$setEnv()}}
|
||||
\item \href{#method-MockShinySession-setReturned}{\code{MockShinySession$setReturned()}}
|
||||
\item \href{#method-MockShinySession-getReturned}{\code{MockShinySession$getReturned()}}
|
||||
\item \href{#method-MockShinySession-genId}{\code{MockShinySession$genId()}}
|
||||
\item \href{#method-MockShinySession-rootScope}{\code{MockShinySession$rootScope()}}
|
||||
\item \href{#method-MockShinySession-unhandledError}{\code{MockShinySession$unhandledError()}}
|
||||
\item \href{#method-MockShinySession-freezeValue}{\code{MockShinySession$freezeValue()}}
|
||||
\item \href{#method-MockShinySession-onSessionEnded}{\code{MockShinySession$onSessionEnded()}}
|
||||
\item \href{#method-MockShinySession-registerDownload}{\code{MockShinySession$registerDownload()}}
|
||||
\item \href{#method-MockShinySession-getCurrentOutputInfo}{\code{MockShinySession$getCurrentOutputInfo()}}
|
||||
\item \href{#method-MockShinySession-clone}{\code{MockShinySession$clone()}}
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-new"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-new}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-new"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-new}{}}}
|
||||
\subsection{Method \code{new()}}{
|
||||
Create a new MockShinySession.
|
||||
\subsection{Usage}{
|
||||
@@ -127,8 +127,8 @@ Create a new MockShinySession.
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-onFlush"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-onFlush}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-onFlush"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-onFlush}{}}}
|
||||
\subsection{Method \code{onFlush()}}{
|
||||
Define a callback to be invoked before a reactive flush
|
||||
\subsection{Usage}{
|
||||
@@ -146,8 +146,8 @@ Define a callback to be invoked before a reactive flush
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-onFlushed"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-onFlushed}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-onFlushed"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-onFlushed}{}}}
|
||||
\subsection{Method \code{onFlushed()}}{
|
||||
Define a callback to be invoked after a reactive flush
|
||||
\subsection{Usage}{
|
||||
@@ -165,8 +165,8 @@ Define a callback to be invoked after a reactive flush
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-onEnded"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-onEnded}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-onEnded"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-onEnded}{}}}
|
||||
\subsection{Method \code{onEnded()}}{
|
||||
Define a callback to be invoked when the session ends
|
||||
\subsection{Usage}{
|
||||
@@ -182,8 +182,8 @@ Define a callback to be invoked when the session ends
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-isEnded"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-isEnded}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-isEnded"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-isEnded}{}}}
|
||||
\subsection{Method \code{isEnded()}}{
|
||||
Returns \code{FALSE} if the session has not yet been closed
|
||||
\subsection{Usage}{
|
||||
@@ -192,8 +192,8 @@ Returns \code{FALSE} if the session has not yet been closed
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-isClosed"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-isClosed}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-isClosed"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-isClosed}{}}}
|
||||
\subsection{Method \code{isClosed()}}{
|
||||
Returns \code{FALSE} if the session has not yet been closed
|
||||
\subsection{Usage}{
|
||||
@@ -202,8 +202,8 @@ Returns \code{FALSE} if the session has not yet been closed
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-close"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-close}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-close"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-close}{}}}
|
||||
\subsection{Method \code{close()}}{
|
||||
Closes the session
|
||||
\subsection{Usage}{
|
||||
@@ -212,8 +212,8 @@ Closes the session
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-cycleStartAction"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-cycleStartAction}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-cycleStartAction"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-cycleStartAction}{}}}
|
||||
\subsection{Method \code{cycleStartAction()}}{
|
||||
Unsophisticated mock implementation that merely invokes
|
||||
\subsection{Usage}{
|
||||
@@ -229,8 +229,8 @@ Unsophisticated mock implementation that merely invokes
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-fileUrl"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-fileUrl}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-fileUrl"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-fileUrl}{}}}
|
||||
\subsection{Method \code{fileUrl()}}{
|
||||
Base64-encode the given file. Needed for image rendering.
|
||||
\subsection{Usage}{
|
||||
@@ -250,8 +250,8 @@ Base64-encode the given file. Needed for image rendering.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-setInputs"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-setInputs}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-setInputs"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-setInputs}{}}}
|
||||
\subsection{Method \code{setInputs()}}{
|
||||
Sets reactive values associated with the \code{session$inputs}
|
||||
object and flushes the reactives.
|
||||
@@ -280,8 +280,8 @@ session$setInputs(x=1, y=2)
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-.scheduleTask"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-.scheduleTask}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-.scheduleTask"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-.scheduleTask}{}}}
|
||||
\subsection{Method \code{.scheduleTask()}}{
|
||||
An internal method which shouldn't be used by others.
|
||||
Schedules \code{callback} for execution after some number of \code{millis}
|
||||
@@ -301,8 +301,8 @@ milliseconds.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-elapse"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-elapse}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-elapse"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-elapse}{}}}
|
||||
\subsection{Method \code{elapse()}}{
|
||||
Simulate the passing of time by the given number of milliseconds.
|
||||
\subsection{Usage}{
|
||||
@@ -318,8 +318,8 @@ Simulate the passing of time by the given number of milliseconds.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-.now"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-.now}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-.now"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-.now}{}}}
|
||||
\subsection{Method \code{.now()}}{
|
||||
An internal method which shouldn't be used by others.
|
||||
\subsection{Usage}{
|
||||
@@ -331,8 +331,8 @@ Elapsed time in milliseconds.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-defineOutput"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-defineOutput}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-defineOutput"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-defineOutput}{}}}
|
||||
\subsection{Method \code{defineOutput()}}{
|
||||
An internal method which shouldn't be used by others.
|
||||
Defines an output in a way that sets private$currentOutputName
|
||||
@@ -354,8 +354,8 @@ appropriately.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-getOutput"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-getOutput}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-getOutput"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-getOutput}{}}}
|
||||
\subsection{Method \code{getOutput()}}{
|
||||
An internal method which shouldn't be used by others. Forces
|
||||
evaluation of any reactive dependencies of the output function.
|
||||
@@ -376,8 +376,8 @@ output.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-ns"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-ns}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-ns"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-ns}{}}}
|
||||
\subsection{Method \code{ns()}}{
|
||||
Returns the given id prefixed by this namespace's id.
|
||||
\subsection{Usage}{
|
||||
@@ -396,8 +396,8 @@ The id with a namespace prefix.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-flushReact"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-flushReact}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-flushReact"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-flushReact}{}}}
|
||||
\subsection{Method \code{flushReact()}}{
|
||||
Trigger a reactive flush right now.
|
||||
\subsection{Usage}{
|
||||
@@ -406,8 +406,8 @@ Trigger a reactive flush right now.
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-makeScope"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-makeScope}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-makeScope"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-makeScope}{}}}
|
||||
\subsection{Method \code{makeScope()}}{
|
||||
Create and return a namespace-specific session proxy.
|
||||
\subsection{Usage}{
|
||||
@@ -426,8 +426,8 @@ A new session proxy.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-setEnv"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-setEnv}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-setEnv"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-setEnv}{}}}
|
||||
\subsection{Method \code{setEnv()}}{
|
||||
Set the environment associated with a testServer() call, but
|
||||
only if it has not previously been set. This ensures that only the
|
||||
@@ -449,8 +449,8 @@ The provided \code{env}.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-setReturned"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-setReturned}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-setReturned"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-setReturned}{}}}
|
||||
\subsection{Method \code{setReturned()}}{
|
||||
Set the value returned by the module call and proactively
|
||||
flush. Note that this method may be called multiple times if modules
|
||||
@@ -472,8 +472,8 @@ The provided \code{value}.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-getReturned"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-getReturned}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-getReturned"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-getReturned}{}}}
|
||||
\subsection{Method \code{getReturned()}}{
|
||||
Get the value returned by the module call.
|
||||
\subsection{Usage}{
|
||||
@@ -485,8 +485,8 @@ The value returned by the module call
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-genId"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-genId}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-genId"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-genId}{}}}
|
||||
\subsection{Method \code{genId()}}{
|
||||
Generate a distinct character identifier for use as a proxy
|
||||
namespace.
|
||||
@@ -499,8 +499,8 @@ A character identifier unique to the current session.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-rootScope"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-rootScope}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-rootScope"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-rootScope}{}}}
|
||||
\subsection{Method \code{rootScope()}}{
|
||||
Provides a way to access the root \code{MockShinySession} from
|
||||
any descendant proxy.
|
||||
@@ -513,8 +513,8 @@ The root \code{MockShinySession}.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-unhandledError"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-unhandledError}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-unhandledError"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-unhandledError}{}}}
|
||||
\subsection{Method \code{unhandledError()}}{
|
||||
Called by observers when a reactive expression errors.
|
||||
\subsection{Usage}{
|
||||
@@ -530,8 +530,8 @@ Called by observers when a reactive expression errors.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-freezeValue"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-freezeValue}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-freezeValue"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-freezeValue}{}}}
|
||||
\subsection{Method \code{freezeValue()}}{
|
||||
Freeze a value until the flush cycle completes.
|
||||
\subsection{Usage}{
|
||||
@@ -549,8 +549,8 @@ Freeze a value until the flush cycle completes.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-onSessionEnded"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-onSessionEnded}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-onSessionEnded"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-onSessionEnded}{}}}
|
||||
\subsection{Method \code{onSessionEnded()}}{
|
||||
Registers the given callback to be invoked when the session
|
||||
is closed (i.e. the connection to the client has been severed). The
|
||||
@@ -570,8 +570,8 @@ guaranteed.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-registerDownload"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-registerDownload}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-registerDownload"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-registerDownload}{}}}
|
||||
\subsection{Method \code{registerDownload()}}{
|
||||
Associated a downloadable file with the session.
|
||||
\subsection{Usage}{
|
||||
@@ -598,8 +598,8 @@ function.)}
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-getCurrentOutputInfo"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-getCurrentOutputInfo}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-getCurrentOutputInfo"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-getCurrentOutputInfo}{}}}
|
||||
\subsection{Method \code{getCurrentOutputInfo()}}{
|
||||
Get information about the output that is currently being
|
||||
executed.
|
||||
@@ -614,8 +614,8 @@ output, or \code{NULL} if no output is currently executing.
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-clone"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-clone}{}}}
|
||||
\if{html}{\out{<a id="method-MockShinySession-clone"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-MockShinySession-clone}{}}}
|
||||
\subsection{Method \code{clone()}}{
|
||||
The objects of this class are cloneable with this method.
|
||||
\subsection{Usage}{
|
||||
|
||||
@@ -62,19 +62,19 @@ shinyApp(ui, server)
|
||||
\section{Methods}{
|
||||
\subsection{Public methods}{
|
||||
\itemize{
|
||||
\item \href{#method-new}{\code{Progress$new()}}
|
||||
\item \href{#method-set}{\code{Progress$set()}}
|
||||
\item \href{#method-inc}{\code{Progress$inc()}}
|
||||
\item \href{#method-getMin}{\code{Progress$getMin()}}
|
||||
\item \href{#method-getMax}{\code{Progress$getMax()}}
|
||||
\item \href{#method-getValue}{\code{Progress$getValue()}}
|
||||
\item \href{#method-close}{\code{Progress$close()}}
|
||||
\item \href{#method-clone}{\code{Progress$clone()}}
|
||||
\item \href{#method-Progress-new}{\code{Progress$new()}}
|
||||
\item \href{#method-Progress-set}{\code{Progress$set()}}
|
||||
\item \href{#method-Progress-inc}{\code{Progress$inc()}}
|
||||
\item \href{#method-Progress-getMin}{\code{Progress$getMin()}}
|
||||
\item \href{#method-Progress-getMax}{\code{Progress$getMax()}}
|
||||
\item \href{#method-Progress-getValue}{\code{Progress$getValue()}}
|
||||
\item \href{#method-Progress-close}{\code{Progress$close()}}
|
||||
\item \href{#method-Progress-clone}{\code{Progress$clone()}}
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-new"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-new}{}}}
|
||||
\if{html}{\out{<a id="method-Progress-new"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-Progress-new}{}}}
|
||||
\subsection{Method \code{new()}}{
|
||||
Creates a new progress panel (but does not display it).
|
||||
\subsection{Usage}{
|
||||
@@ -107,8 +107,8 @@ is for backward-compatibility).}
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-set"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-set}{}}}
|
||||
\if{html}{\out{<a id="method-Progress-set"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-Progress-set}{}}}
|
||||
\subsection{Method \code{set()}}{
|
||||
Updates the progress panel. When called the first time, the
|
||||
progress panel is displayed.
|
||||
@@ -135,8 +135,8 @@ relative to \code{message}.}
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-inc"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-inc}{}}}
|
||||
\if{html}{\out{<a id="method-Progress-inc"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-Progress-inc}{}}}
|
||||
\subsection{Method \code{inc()}}{
|
||||
Like \code{set}, this updates the progress panel. The difference
|
||||
is that \code{inc} increases the progress bar by \code{amount}, instead of
|
||||
@@ -163,8 +163,8 @@ relative to \code{message}.}
|
||||
}
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-getMin"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-getMin}{}}}
|
||||
\if{html}{\out{<a id="method-Progress-getMin"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-Progress-getMin}{}}}
|
||||
\subsection{Method \code{getMin()}}{
|
||||
Returns the minimum value.
|
||||
\subsection{Usage}{
|
||||
@@ -173,8 +173,8 @@ Returns the minimum value.
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-getMax"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-getMax}{}}}
|
||||
\if{html}{\out{<a id="method-Progress-getMax"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-Progress-getMax}{}}}
|
||||
\subsection{Method \code{getMax()}}{
|
||||
Returns the maximum value.
|
||||
\subsection{Usage}{
|
||||
@@ -183,8 +183,8 @@ Returns the maximum value.
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-getValue"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-getValue}{}}}
|
||||
\if{html}{\out{<a id="method-Progress-getValue"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-Progress-getValue}{}}}
|
||||
\subsection{Method \code{getValue()}}{
|
||||
Returns the current value.
|
||||
\subsection{Usage}{
|
||||
@@ -193,8 +193,8 @@ Returns the current value.
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-close"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-close}{}}}
|
||||
\if{html}{\out{<a id="method-Progress-close"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-Progress-close}{}}}
|
||||
\subsection{Method \code{close()}}{
|
||||
Removes the progress panel. Future calls to \code{set} and
|
||||
\code{close} will be ignored.
|
||||
@@ -204,8 +204,8 @@ Removes the progress panel. Future calls to \code{set} and
|
||||
|
||||
}
|
||||
\if{html}{\out{<hr>}}
|
||||
\if{html}{\out{<a id="method-clone"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-clone}{}}}
|
||||
\if{html}{\out{<a id="method-Progress-clone"></a>}}
|
||||
\if{latex}{\out{\hypertarget{method-Progress-clone}{}}}
|
||||
\subsection{Method \code{clone()}}{
|
||||
The objects of this class are cloneable with this method.
|
||||
\subsection{Usage}{
|
||||
|
||||
@@ -40,7 +40,9 @@ sense, namely:
|
||||
|
||||
In the example here, the \code{bindCache()} key consists of \code{input$x} and
|
||||
\code{input$y} combined, and the value is \code{input$x * input$y}. In this simple
|
||||
example, for any given key, there is only one possible returned value.\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{ input$x * input$y \}) \%>\%
|
||||
example, for any given key, there is only one possible returned value.
|
||||
|
||||
\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{ input$x * input$y \}) \%>\%
|
||||
bindCache(input$x, input$y)
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
@@ -63,7 +65,9 @@ to do some sort of reduction on the data that still captures information
|
||||
about whether a value can be retrieved from the cache. For example, if you
|
||||
have a large data set with timestamps, it might make sense to extract the
|
||||
most recent timestamp and return that. Then, instead of hashing the entire
|
||||
data object, the cached reactive only needs to hash the timestamp.\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{ compute(bigdata()) \} \%>\%
|
||||
data object, the cached reactive only needs to hash the timestamp.
|
||||
|
||||
\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{ compute(bigdata()) \} \%>\%
|
||||
bindCache(\{ extract_most_recent_time(bigdata()) \})
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
@@ -105,7 +109,9 @@ cache key is not too expensive.
|
||||
Remember that the key is \emph{reactive}, so it is not re-executed every single
|
||||
time that someone accesses the cached reactive. It is only re-executed if
|
||||
it has been invalidated by one of the reactives it depends on. For
|
||||
example, suppose we have this cached reactive:\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{ input$x * input$y \}) \%>\%
|
||||
example, suppose we have this cached reactive:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{ input$x * input$y \}) \%>\%
|
||||
bindCache(input$x, input$y)
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
@@ -154,24 +160,30 @@ persists beyond the current R session.
|
||||
To use different settings for an application-scoped cache, you can call
|
||||
\code{\link[=shinyOptions]{shinyOptions()}} at the top of your app.R, server.R, or
|
||||
global.R. For example, this will create a cache with 500 MB of space
|
||||
instead of the default 200 MB:\preformatted{shinyOptions(cache = cachem::cache_mem(max_size = 500e6))
|
||||
}
|
||||
instead of the default 200 MB:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{shinyOptions(cache = cachem::cache_mem(max_size = 500e6))
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
To use different settings for a session-scoped cache, you can set
|
||||
\code{self$cache} at the top of your server function. By default, it will create
|
||||
a 200 MB memory cache for each session, but you can replace it with
|
||||
something different. To use the session-scoped cache, you must also call
|
||||
\code{bindCache()} with \code{cache="session"}. This will create a 100 MB cache for
|
||||
the session:\preformatted{function(input, output, session) \{
|
||||
the session:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{function(input, output, session) \{
|
||||
session$cache <- cachem::cache_mem(max_size = 100e6)
|
||||
...
|
||||
\}
|
||||
}
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
If you want to use a cache that is shared across multiple R processes, you
|
||||
can use a \code{\link[cachem:cache_disk]{cachem::cache_disk()}}. You can create a application-level shared
|
||||
cache by putting this at the top of your app.R, server.R, or global.R:\preformatted{shinyOptions(cache = cachem::cache_disk(file.path(dirname(tempdir()), "myapp-cache"))
|
||||
}
|
||||
cache by putting this at the top of your app.R, server.R, or global.R:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{shinyOptions(cache = cachem::cache_disk(file.path(dirname(tempdir()), "myapp-cache"))
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
This will create a subdirectory in your system temp directory named
|
||||
\code{myapp-cache} (replace \code{myapp-cache} with a unique name of
|
||||
@@ -181,8 +193,10 @@ stops of the R process, as long as you do not reboot.
|
||||
|
||||
To have the cache persist even across multiple reboots, you can create the
|
||||
cache in a location outside of the temp directory. For example, it could
|
||||
be a subdirectory of the application:\preformatted{shinyOptions(cache = cachem::cache_disk("./myapp-cache"))
|
||||
}
|
||||
be a subdirectory of the application:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{shinyOptions(cache = cachem::cache_disk("./myapp-cache"))
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
In this case, resetting the cache will have to be done manually, by deleting
|
||||
the directory.
|
||||
@@ -247,9 +261,11 @@ You may need to provide a \code{cacheHint} to \code{\link[=createRenderFunction]
|
||||
\code{htmlwidgets::shinyRenderWidget()}, if you've authored an htmlwidget) in
|
||||
order for \code{bindCache()} to correctly compute a cache key.
|
||||
|
||||
The potential problem is a cache collision. Consider the following:\preformatted{output$x1 <- renderText(\{ input$x \}) \%>\% bindCache(input$x)
|
||||
The potential problem is a cache collision. Consider the following:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{output$x1 <- renderText(\{ input$x \}) \%>\% bindCache(input$x)
|
||||
output$x2 <- renderText(\{ input$x * 2 \}) \%>\% bindCache(input$x)
|
||||
}
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
Both \code{output$x1} and \code{output$x2} use \code{input$x} as part of their cache key,
|
||||
but if it were the only thing used in the cache key, then the two outputs
|
||||
@@ -258,7 +274,9 @@ this, a \emph{cache hint} is automatically added when \code{\link[=renderText]{r
|
||||
\code{\link[=createRenderFunction]{createRenderFunction()}}. The cache hint is used as part of the actual
|
||||
cache key, in addition to the one passed to \code{bindCache()} by the user. The
|
||||
cache hint can be viewed by calling the internal Shiny function
|
||||
\code{extractCacheHint()}:\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- renderText(\{ input$x \})
|
||||
\code{extractCacheHint()}:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- renderText(\{ input$x \})
|
||||
shiny:::extractCacheHint(r)
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
@@ -289,7 +307,9 @@ that may influence the final value.
|
||||
For \pkg{htmlwidgets}, it will try to automatically infer a cache hint;
|
||||
again, you can inspect the cache hint with \code{shiny:::extractCacheHint()} and
|
||||
also test it in an application. If you do need to explicitly provide a
|
||||
cache hint, pass it to \code{shinyRenderWidget}. For example:\preformatted{renderMyWidget <- function(expr) \{
|
||||
cache hint, pass it to \code{shinyRenderWidget}. For example:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{renderMyWidget <- function(expr) \{
|
||||
q <- rlang::enquo0(expr)
|
||||
|
||||
htmlwidgets::shinyRenderWidget(
|
||||
@@ -299,7 +319,7 @@ cache hint, pass it to \code{shinyRenderWidget}. For example:\preformatted{rende
|
||||
cacheHint = list(label = "myWidget", userQuo = q)
|
||||
)
|
||||
\}
|
||||
}
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
If your \code{render} function sets any internal state, you may find it useful
|
||||
in your call to \code{\link[=createRenderFunction]{createRenderFunction()}} to use
|
||||
@@ -330,8 +350,10 @@ For developers of such code, they should call \code{\link[=createRenderFunction]
|
||||
|
||||
When \code{bindCache()} is used with \code{renderPlot()}, the \code{height} and \code{width}
|
||||
passed to the original \code{renderPlot()} are ignored. They are superseded by
|
||||
\code{sizePolicy} argument passed to `bindCache. The default is:\preformatted{sizePolicy = sizeGrowthRatio(width = 400, height = 400, growthRate = 1.2)
|
||||
}
|
||||
\code{sizePolicy} argument passed to `bindCache. The default is:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{sizePolicy = sizeGrowthRatio(width = 400, height = 400, growthRate = 1.2)
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
\code{sizePolicy} must be a function that takes a two-element numeric vector as
|
||||
input, representing the width and height of the \verb{<img>} element in the
|
||||
|
||||
@@ -171,7 +171,9 @@ user sets both \code{x} and \code{y}, and then clicks on an \link{actionButton}
|
||||
\code{go}.
|
||||
|
||||
To use both caching and events, the object should first be passed to
|
||||
\code{bindCache()}, then \code{bindEvent()}. For example:\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{
|
||||
\code{bindCache()}, then \code{bindEvent()}. For example:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{
|
||||
Sys.sleep(2) # Pretend this is an expensive computation
|
||||
input$x * input$y
|
||||
\}) \%>\%
|
||||
|
||||
@@ -28,7 +28,7 @@ This will be used as the lang in the \code{<html>} tag, as in \code{<html lang="
|
||||
The default (NULL) results in an empty string.}
|
||||
}
|
||||
\value{
|
||||
A UI defintion that can be passed to the \link{shinyUI} function.
|
||||
A UI definition that can be passed to the \link{shinyUI} function.
|
||||
}
|
||||
\description{
|
||||
Create a Shiny UI page that loads the CSS and JavaScript for
|
||||
|
||||
@@ -101,7 +101,9 @@ displays a message once every 8 hrs (by default)
|
||||
value and Developer message. This registration method allows package
|
||||
authors to write one message in a single location.
|
||||
|
||||
For example, the following Shiny Developer Mode options are registered:\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Reload the Shiny app when a sourced R file changes
|
||||
For example, the following Shiny Developer Mode options are registered:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Reload the Shiny app when a sourced R file changes
|
||||
register_devmode_option(
|
||||
"shiny.autoreload",
|
||||
"Turning on shiny autoreload. To disable, call `options(shiny.autoreload = FALSE)`",
|
||||
@@ -126,7 +128,9 @@ register_devmode_option(
|
||||
Other known, non-Shiny Developer Mode options:
|
||||
\itemize{
|
||||
\item Sass:
|
||||
}\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Display the full stack trace when errors occur during Shiny app execution
|
||||
}
|
||||
|
||||
\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Display the full stack trace when errors occur during Shiny app execution
|
||||
register_devmode_option(
|
||||
"sass.cache",
|
||||
"Turning off sass cache. To use default caching, call `options(sass.cache = TRUE)`",
|
||||
@@ -165,7 +169,9 @@ re-implementing these two functions:
|
||||
|
||||
This function should return \code{TRUE} if \code{getOption("shiny.devmode")} is set.
|
||||
In addition, we strongly recommend that it also checks to make sure
|
||||
\code{testthat} is not testing.\if{html}{\out{<div class="sourceCode r">}}\preformatted{in_devmode <- function() \{
|
||||
\code{testthat} is not testing.
|
||||
|
||||
\if{html}{\out{<div class="sourceCode r">}}\preformatted{in_devmode <- function() \{
|
||||
isTRUE(getOption("shiny.devmode", FALSE)) &&
|
||||
!identical(Sys.getenv("TESTTHAT"), "true")
|
||||
\}
|
||||
@@ -201,7 +207,9 @@ recommend displaying a message (\code{devmode_message}) to \code{stderr()} once
|
||||
hours using \code{\link[rlang:abort]{rlang::inform()}}. This will keep the author up to date as to
|
||||
which Dev Mode options are being altered. To allow developers a chance to
|
||||
disable Dev Mode messages, the message should be skipped if
|
||||
\code{getOption("shiny.devmode.verbose", TRUE)} is not \code{TRUE}.\if{html}{\out{<div class="sourceCode r">}}\preformatted{get_devmode_option <- function(name, default = NULL, devmode_default, devmode_message) \{
|
||||
\code{getOption("shiny.devmode.verbose", TRUE)} is not \code{TRUE}.
|
||||
|
||||
\if{html}{\out{<div class="sourceCode r">}}\preformatted{get_devmode_option <- function(name, default = NULL, devmode_default, devmode_message) \{
|
||||
if (!in_devmode()) \{
|
||||
# Dev Mode disabled, act like `getOption()`
|
||||
return(getOption(name, default = default))
|
||||
|
||||
@@ -40,7 +40,7 @@ deleted from disk. If \code{FALSE} (the default), it will do nothing when
|
||||
finalized.}
|
||||
|
||||
\item{missing}{A value to return when \code{get(key)} is called but the key is not
|
||||
present in the cache. The default is a \code{\link[cachem:reexports]{key_missing()}} object. It is
|
||||
present in the cache. The default is a \code{\link[cachem:key_missing]{key_missing()}} object. It is
|
||||
actually an expression that is evaluated each time there is a cache miss.
|
||||
See section Missing keys for more information.}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
\alias{downloadHandler}
|
||||
\title{File Downloads}
|
||||
\usage{
|
||||
downloadHandler(filename, content, contentType = NA, outputArgs = list())
|
||||
downloadHandler(filename, content, contentType = NULL, outputArgs = list())
|
||||
}
|
||||
\arguments{
|
||||
\item{filename}{A string of the filename, including extension, that the
|
||||
@@ -19,9 +19,9 @@ function.)}
|
||||
|
||||
\item{contentType}{A string of the download's
|
||||
\href{https://en.wikipedia.org/wiki/Internet_media_type}{content type}, for
|
||||
example \code{"text/csv"} or \code{"image/png"}. If \code{NULL} or
|
||||
\code{NA}, the content type will be guessed based on the filename
|
||||
extension, or \code{application/octet-stream} if the extension is unknown.}
|
||||
example \code{"text/csv"} or \code{"image/png"}. If \code{NULL}, the content type
|
||||
will be guessed based on the filename extension, or
|
||||
\code{application/octet-stream} if the extension is unknown.}
|
||||
|
||||
\item{outputArgs}{A list of arguments to be passed through to the implicit
|
||||
call to \code{\link[=downloadButton]{downloadButton()}} when \code{downloadHandler} is used
|
||||
|
||||
@@ -11,7 +11,8 @@ fileInput(
|
||||
accept = NULL,
|
||||
width = NULL,
|
||||
buttonLabel = "Browse...",
|
||||
placeholder = "No file selected"
|
||||
placeholder = "No file selected",
|
||||
capture = NULL
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
@@ -42,6 +43,19 @@ see \code{\link[=validateCssUnit]{validateCssUnit()}}.}
|
||||
object.}
|
||||
|
||||
\item{placeholder}{The text to show before a file has been uploaded.}
|
||||
|
||||
\item{capture}{What source to use for capturing image, audio or video data.
|
||||
This attribute facilitates user access to a device's media capture
|
||||
mechanism, such as a camera, or microphone, from within a file upload
|
||||
control.
|
||||
|
||||
A value of \code{user} indicates that the user-facing camera and/or microphone
|
||||
should be used. A value of \code{environment} specifies that the outward-facing
|
||||
camera and/or microphone should be used.
|
||||
|
||||
By default on most phones, this will accept still photos or video. For
|
||||
still photos only, also use \code{accept="image/*"}. For video only, use
|
||||
\code{accept="video/*"}.}
|
||||
}
|
||||
\description{
|
||||
Create a file upload control that can be used to upload one or more files.
|
||||
|
||||
@@ -28,7 +28,7 @@ This will be used as the lang in the \code{<html>} tag, as in \code{<html lang="
|
||||
The default (NULL) results in an empty string.}
|
||||
}
|
||||
\value{
|
||||
A UI defintion that can be passed to the \link{shinyUI} function.
|
||||
A UI definition that can be passed to the \link{shinyUI} function.
|
||||
}
|
||||
\description{
|
||||
Functions for creating fixed page layouts. A fixed page layout consists of
|
||||
|
||||
@@ -29,7 +29,7 @@ This will be used as the lang in the \code{<html>} tag, as in \code{<html lang="
|
||||
The default (NULL) results in an empty string.}
|
||||
}
|
||||
\value{
|
||||
A UI defintion that can be passed to the \link{shinyUI} function.
|
||||
A UI definition that can be passed to the \link{shinyUI} function.
|
||||
}
|
||||
\description{
|
||||
Functions for creating fluid page layouts. A fluid page layout consists of
|
||||
|
||||
@@ -15,7 +15,7 @@ loadSupport(
|
||||
not supplied, the nearest enclosing directory that is a Shiny app, starting
|
||||
with the current directory, is used.}
|
||||
|
||||
\item{renv}{The environmeny in which the files in the \verb{R/} directory should
|
||||
\item{renv}{The environment in which the files in the \verb{R/} directory should
|
||||
be evaluated.}
|
||||
|
||||
\item{globalrenv}{The environment in which \code{global.R} should be evaluated. If
|
||||
|
||||
@@ -30,7 +30,7 @@ value of \code{evict}. Use \code{Inf} for no limit of number of items.}
|
||||
when a cache pruning occurs. Currently, \code{"lru"} and \code{"fifo"} are supported.}
|
||||
|
||||
\item{missing}{A value to return when \code{get(key)} is called but the key is not
|
||||
present in the cache. The default is a \code{\link[cachem:reexports]{key_missing()}} object. It is
|
||||
present in the cache. The default is a \code{\link[cachem:key_missing]{key_missing()}} object. It is
|
||||
actually an expression that is evaluated each time there is a cache miss.
|
||||
See section Missing keys for more information.}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ is needed if you want to insert/remove or show/hide an entire
|
||||
\item{icon}{Optional icon to appear on a \code{navbarMenu} tab.}
|
||||
}
|
||||
\value{
|
||||
A UI defintion that can be passed to the \link{shinyUI} function.
|
||||
A UI definition that can be passed to the \link{shinyUI} function.
|
||||
}
|
||||
\description{
|
||||
Create a page that contains a top level navigation bar that can be used to
|
||||
|
||||
@@ -14,7 +14,7 @@ pageWithSidebar(headerPanel, sidebarPanel, mainPanel)
|
||||
\item{mainPanel}{The \link{mainPanel} containing outputs}
|
||||
}
|
||||
\value{
|
||||
A UI defintion that can be passed to the \link{shinyUI} function
|
||||
A UI definition that can be passed to the \link{shinyUI} function
|
||||
}
|
||||
\description{
|
||||
\strong{DEPRECATED}: use \code{\link[=fluidPage]{fluidPage()}} and \code{\link[=sidebarLayout]{sidebarLayout()}} instead.
|
||||
|
||||
@@ -52,6 +52,6 @@ below to see their documentation.
|
||||
\describe{
|
||||
\item{fastmap}{\code{\link[fastmap:key_missing]{is.key_missing}}, \code{\link[fastmap]{key_missing}}}
|
||||
|
||||
\item{htmltools}{\code{\link[htmltools]{HTML}}, \code{\link[htmltools:builder]{a}}, \code{\link[htmltools:builder]{br}}, \code{\link[htmltools:builder]{code}}, \code{\link[htmltools:builder]{div}}, \code{\link[htmltools:builder]{em}}, \code{\link[htmltools:builder]{h1}}, \code{\link[htmltools:builder]{h2}}, \code{\link[htmltools:builder]{h3}}, \code{\link[htmltools:builder]{h4}}, \code{\link[htmltools:builder]{h5}}, \code{\link[htmltools:builder]{h6}}, \code{\link[htmltools:builder]{hr}}, \code{\link[htmltools]{htmlTemplate}}, \code{\link[htmltools:builder]{img}}, \code{\link[htmltools:include]{includeCSS}}, \code{\link[htmltools:include]{includeHTML}}, \code{\link[htmltools:include]{includeMarkdown}}, \code{\link[htmltools:include]{includeScript}}, \code{\link[htmltools:include]{includeText}}, \code{\link[htmltools:singleton]{is.singleton}}, \code{\link[htmltools:builder]{p}}, \code{\link[htmltools:builder]{pre}}, \code{\link[htmltools]{singleton}}, \code{\link[htmltools:builder]{span}}, \code{\link[htmltools:builder]{strong}}, \code{\link[htmltools]{suppressDependencies}}, \code{\link[htmltools:builder]{tag}}, \code{\link[htmltools]{tagAppendAttributes}}, \code{\link[htmltools]{tagAppendChild}}, \code{\link[htmltools:tagAppendChild]{tagAppendChildren}}, \code{\link[htmltools:tagAppendAttributes]{tagGetAttribute}}, \code{\link[htmltools:tagAppendAttributes]{tagHasAttribute}}, \code{\link[htmltools]{tagList}}, \code{\link[htmltools:tagAppendChild]{tagSetChildren}}, \code{\link[htmltools:builder]{tags}}, \code{\link[htmltools]{validateCssUnit}}, \code{\link[htmltools]{withTags}}}
|
||||
\item{htmltools}{\code{\link[htmltools:builder]{a}}, \code{\link[htmltools:builder]{br}}, \code{\link[htmltools:builder]{code}}, \code{\link[htmltools:builder]{div}}, \code{\link[htmltools:builder]{em}}, \code{\link[htmltools:builder]{h1}}, \code{\link[htmltools:builder]{h2}}, \code{\link[htmltools:builder]{h3}}, \code{\link[htmltools:builder]{h4}}, \code{\link[htmltools:builder]{h5}}, \code{\link[htmltools:builder]{h6}}, \code{\link[htmltools:builder]{hr}}, \code{\link[htmltools]{HTML}}, \code{\link[htmltools]{htmlTemplate}}, \code{\link[htmltools:builder]{img}}, \code{\link[htmltools:include]{includeCSS}}, \code{\link[htmltools:include]{includeHTML}}, \code{\link[htmltools:include]{includeMarkdown}}, \code{\link[htmltools:include]{includeScript}}, \code{\link[htmltools:include]{includeText}}, \code{\link[htmltools:singleton]{is.singleton}}, \code{\link[htmltools:builder]{p}}, \code{\link[htmltools:builder]{pre}}, \code{\link[htmltools]{singleton}}, \code{\link[htmltools:builder]{span}}, \code{\link[htmltools:builder]{strong}}, \code{\link[htmltools]{suppressDependencies}}, \code{\link[htmltools:builder]{tag}}, \code{\link[htmltools]{tagAppendAttributes}}, \code{\link[htmltools]{tagAppendChild}}, \code{\link[htmltools:tagAppendChild]{tagAppendChildren}}, \code{\link[htmltools:tagAppendAttributes]{tagGetAttribute}}, \code{\link[htmltools:tagAppendAttributes]{tagHasAttribute}}, \code{\link[htmltools]{tagList}}, \code{\link[htmltools:builder]{tags}}, \code{\link[htmltools:tagAppendChild]{tagSetChildren}}, \code{\link[htmltools]{validateCssUnit}}, \code{\link[htmltools]{withTags}}}
|
||||
}}
|
||||
|
||||
|
||||
12
man/req.Rd
12
man/req.Rd
@@ -25,26 +25,30 @@ nor displayed in the Shiny app's UI).
|
||||
\details{
|
||||
The \code{req} function was designed to be used in one of two ways. The first
|
||||
is to call it like a statement (ignoring its return value) before attempting
|
||||
operations using the required values:\preformatted{rv <- reactiveValues(state = FALSE)
|
||||
operations using the required values:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{rv <- reactiveValues(state = FALSE)
|
||||
r <- reactive(\{
|
||||
req(input$a, input$b, rv$state)
|
||||
# Code that uses input$a, input$b, and/or rv$state...
|
||||
\})
|
||||
}
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
In this example, if \code{r()} is called and any of \code{input$a},
|
||||
\code{input$b}, and \code{rv$state} are \code{NULL}, \code{FALSE}, \code{""},
|
||||
etc., then the \code{req} call will trigger an error that propagates all the
|
||||
way up to whatever render block or observer is executing.
|
||||
|
||||
The second is to use it to wrap an expression that must be truthy:\preformatted{output$plot <- renderPlot(\{
|
||||
The second is to use it to wrap an expression that must be truthy:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{output$plot <- renderPlot(\{
|
||||
if (req(input$plotType) == "histogram") \{
|
||||
hist(dataset())
|
||||
\} else if (input$plotType == "scatter") \{
|
||||
qplot(dataset(), aes(x = x, y = y))
|
||||
\}
|
||||
\})
|
||||
}
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
In this example, \code{req(input$plotType)} first checks that
|
||||
\code{input$plotType} is truthy, and if so, returns it. This is a convenient
|
||||
|
||||
@@ -37,7 +37,7 @@ ports will be tried.}
|
||||
|
||||
\item{launch.browser}{If true, the system's default web browser will be
|
||||
launched automatically after the app is started. Defaults to true in
|
||||
interactive sessions only. This value of this parameter can also be a
|
||||
interactive sessions only. The value of this parameter can also be a
|
||||
function to call with the application's URL.}
|
||||
|
||||
\item{host}{The IPv4 address that the application should listen on. Defaults
|
||||
|
||||
@@ -13,7 +13,7 @@ runGist(gist, destdir = NULL, ...)
|
||||
runGitHub(
|
||||
repo,
|
||||
username = getOption("github.user"),
|
||||
ref = "master",
|
||||
ref = "HEAD",
|
||||
subdir = NULL,
|
||||
destdir = NULL,
|
||||
...
|
||||
@@ -47,7 +47,8 @@ all valid values.}
|
||||
\code{"username/repo"}, \code{username} will be taken from \code{repo}.}
|
||||
|
||||
\item{ref}{Desired git reference. Could be a commit, tag, or branch name.
|
||||
Defaults to \code{"master"}.}
|
||||
Defaults to \code{"HEAD"}, which means the default branch on GitHub, typically
|
||||
\code{"main"} or \code{"master"}.}
|
||||
}
|
||||
\description{
|
||||
\code{runUrl()} downloads and launches a Shiny application that is hosted at
|
||||
|
||||
@@ -10,7 +10,7 @@ shinyAppTemplate(path = NULL, examples = "default", dryrun = FALSE)
|
||||
\item{path}{Path to create new shiny application template.}
|
||||
|
||||
\item{examples}{Either one of "default", "ask", "all", or any combination of
|
||||
"app", "rdir", "module", "shinytest", and "testthat". In an
|
||||
"app", "rdir", "module", and "tests". In an
|
||||
interactive session, "default" falls back to "ask"; in a non-interactive
|
||||
session, "default" falls back to "all". With "ask", this function will
|
||||
prompt the user to select which template items will be added to the new app
|
||||
@@ -25,30 +25,31 @@ This function populates a directory with files for a Shiny application.
|
||||
}
|
||||
\details{
|
||||
In an interactive R session, this function will, by default, prompt the user
|
||||
to select which components to add to the application. Choices are\preformatted{1: All
|
||||
to select which components to add to the application. Choices are
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{1: All
|
||||
2: app.R : Main application file
|
||||
3: R/example.R : Helper file with R code
|
||||
4: R/example-module.R : Example module
|
||||
5: tests/shinytest/ : Tests using the shinytest package
|
||||
6: tests/testthat/ : Tests using the testthat package
|
||||
}
|
||||
5: tests/testthat/ : Tests using the testthat and shinytest2 package
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
If option 1 is selected, the full example application including the
|
||||
following files and directories is created:\preformatted{appdir/
|
||||
following files and directories is created:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{appdir/
|
||||
|- app.R
|
||||
|- R
|
||||
| |- example-module.R
|
||||
| `- example.R
|
||||
`- tests
|
||||
|- shinytest.R
|
||||
|- shinytest
|
||||
| `- mytest.R
|
||||
|- testthat.R
|
||||
`- testthat
|
||||
|- test-examplemodule.R
|
||||
|- test-server.R
|
||||
|- test-shinytest2.R
|
||||
`- test-sort.R
|
||||
}
|
||||
}\if{html}{\out{</div>}}
|
||||
|
||||
Some notes about these files:
|
||||
\itemize{
|
||||
@@ -62,15 +63,15 @@ and the second contains code for module created by the
|
||||
\item \verb{tests/} contains various tests for the application. You may
|
||||
choose to use or remove any of them. They can be executed by the
|
||||
\code{\link[=runTests]{runTests()}} function.
|
||||
\item \code{tests/shinytest.R} is a test runner for test files in the
|
||||
\verb{tests/shinytest/} directory.
|
||||
\item \code{tests/shinytest/mytest.R} is a test that uses the
|
||||
\href{https://rstudio.github.io/shinytest/}{shinytest} package to do
|
||||
snapshot-based testing.
|
||||
\item \code{tests/testthat.R} is a test runner for test files in the
|
||||
\verb{tests/testthat/} directory using the \href{https://testthat.r-lib.org/}{testthat} package.
|
||||
\verb{tests/testthat/} directory using the
|
||||
\href{https://rstudio.github.io/shinytest2/reference/test_app.html}{shinytest2}
|
||||
package.
|
||||
\item \code{tests/testthat/test-examplemodule.R} is a test for an application's module server function.
|
||||
\item \code{tests/testthat/test-server.R} is a test for the application's server code
|
||||
\item \code{tests/testthat/test-shinytest2.R} is a test that uses the
|
||||
\href{https://rstudio.github.io/shinytest2/}{shinytest2} package to do
|
||||
snapshot-based testing.
|
||||
\item \code{tests/testthat/test-sort.R} is a test for a supporting function in the \verb{R/} directory.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,10 @@ then jQuery 3.6.0 is used.}
|
||||
numbers to JSON format to send to the client web browser.}
|
||||
\item{shiny.launch.browser (defaults to \code{interactive()})}{A boolean which controls the default behavior
|
||||
when an app is run. See \code{\link[=runApp]{runApp()}} for more information.}
|
||||
\item{shiny.mathjax.url (defaults to \code{"https://mathjax.rstudio.com/latest/MathJax.js"})}{
|
||||
The URL that should be used to load MathJax, via \code{\link[=withMathJax]{withMathJax()}}.}
|
||||
\item{shiny.mathjax.config (defaults to \code{"config=TeX-AMS-MML_HTMLorMML"})}{The querystring
|
||||
used to load MathJax, via \code{\link[=withMathJax]{withMathJax()}}.}
|
||||
\item{shiny.maxRequestSize (defaults to 5MB)}{This is a number which specifies the maximum
|
||||
web request size, which serves as a size limit for file uploads.}
|
||||
\item{shiny.minified (defaults to \code{TRUE})}{By default
|
||||
@@ -104,6 +108,9 @@ should only be used for debugging or demonstrations of reactivity at the
|
||||
console.}
|
||||
\item{shiny.testmode (defaults to \code{FALSE})}{If \code{TRUE}, then various features for testing Shiny
|
||||
applications are enabled.}
|
||||
\item{shiny.snapshotsortc (defaults to \code{FALSE})}{If \code{TRUE}, test snapshot keys
|
||||
for \pkg{shinytest} will be sorted consistently using the C locale. Snapshots
|
||||
retrieved by \pkg{shinytest2} will always sort using the C locale.}
|
||||
\item{shiny.trace (defaults to \code{FALSE})}{Print messages sent between the R server and the web
|
||||
browser client to the R console. This is useful for debugging. Possible
|
||||
values are \code{"send"} (only print messages sent to the client),
|
||||
|
||||
@@ -33,17 +33,7 @@ types (such as logicals and numbers) will be coerced to strings.}
|
||||
|
||||
\item{inline}{If \code{TRUE}, render the choices inline (i.e. horizontally)}
|
||||
|
||||
\item{choiceNames}{List of names and values, respectively,
|
||||
that are displayed to the user in the app and correspond to the each
|
||||
choice (for this reason, \code{choiceNames} and \code{choiceValues}
|
||||
must have the same length). If either of these arguments is
|
||||
provided, then the other \emph{must} be provided and \code{choices}
|
||||
\emph{must not} be provided. The advantage of using both of these over
|
||||
a named list for \code{choices} is that \code{choiceNames} allows any
|
||||
type of UI object to be passed through (tag objects, icons, HTML code,
|
||||
...), instead of just simple text. See Examples.}
|
||||
|
||||
\item{choiceValues}{List of names and values, respectively,
|
||||
\item{choiceNames, choiceValues}{List of names and values, respectively,
|
||||
that are displayed to the user in the app and correspond to the each
|
||||
choice (for this reason, \code{choiceNames} and \code{choiceValues}
|
||||
must have the same length). If either of these arguments is
|
||||
|
||||
@@ -35,16 +35,7 @@ use \code{character(0)}.}
|
||||
|
||||
\item{inline}{If \code{TRUE}, render the choices inline (i.e. horizontally)}
|
||||
|
||||
\item{choiceNames}{List of names and values, respectively, that
|
||||
are displayed to the user in the app and correspond to the each choice (for
|
||||
this reason, \code{choiceNames} and \code{choiceValues} must have the same length).
|
||||
If either of these arguments is provided, then the other \emph{must} be provided
|
||||
and \code{choices} \emph{must not} be provided. The advantage of using both of these
|
||||
over a named list for \code{choices} is that \code{choiceNames} allows any type of UI
|
||||
object to be passed through (tag objects, icons, HTML code, ...), instead
|
||||
of just simple text. See Examples.}
|
||||
|
||||
\item{choiceValues}{List of names and values, respectively, that
|
||||
\item{choiceNames, choiceValues}{List of names and values, respectively, that
|
||||
are displayed to the user in the app and correspond to the each choice (for
|
||||
this reason, \code{choiceNames} and \code{choiceValues} must have the same length).
|
||||
If either of these arguments is provided, then the other \emph{must} be provided
|
||||
|
||||
@@ -29,10 +29,7 @@ updateSliderInput(
|
||||
create a regular slider; a length two vector will create a double-ended
|
||||
range slider. Must lie between \code{min} and \code{max}.}
|
||||
|
||||
\item{min}{The minimum and maximum values (inclusive) that can be
|
||||
selected.}
|
||||
|
||||
\item{max}{The minimum and maximum values (inclusive) that can be
|
||||
\item{min, max}{The minimum and maximum values (inclusive) that can be
|
||||
selected.}
|
||||
|
||||
\item{step}{Specifies the interval between each selectable value on the
|
||||
|
||||
@@ -55,10 +55,12 @@ can create your own validation test functions. A passing test should return
|
||||
to display to the user, or if the failure should happen silently, \code{FALSE}.
|
||||
|
||||
Alternatively you can use \code{validate()} within an \code{if} statement, which is
|
||||
particularly useful for more complex conditions:\preformatted{if (input$x < 0 && input$choice == "positive") \{
|
||||
particularly useful for more complex conditions:
|
||||
|
||||
\if{html}{\out{<div class="sourceCode">}}\preformatted{if (input$x < 0 && input$choice == "positive") \{
|
||||
validate("If choice is positive then x must be greater than 0")
|
||||
\}
|
||||
}
|
||||
}\if{html}{\out{</div>}}
|
||||
}
|
||||
|
||||
\examples{
|
||||
|
||||
@@ -76,10 +76,10 @@ value when it is a single choice input and the empty string is not in the
|
||||
The resulting server \code{input} value will be returned as:
|
||||
\itemize{
|
||||
\item A symbol if \code{multiple = FALSE}. The \code{input} value should be
|
||||
used with rlang's \code{\link[rlang:nse-force]{rlang::!!()}}. For example,
|
||||
used with rlang's \code{\link[rlang:injection-operator]{rlang::!!()}}. For example,
|
||||
\code{ggplot2::aes(!!input$variable)}.
|
||||
\item A list of symbols if \code{multiple = TRUE}. The \code{input} value
|
||||
should be used with rlang's \code{\link[rlang:nse-force]{rlang::!!!()}} to expand
|
||||
should be used with rlang's \code{\link[rlang:splice-operator]{rlang::!!!()}} to expand
|
||||
the symbol list as individual arguments. For example,
|
||||
\code{dplyr::select(mtcars, !!!input$variabls)} which is
|
||||
equivalent to \code{dplyr::select(mtcars, !!input$variabls[[1]], !!input$variabls[[2]], ..., !!input$variabls[[length(input$variabls)]])}.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"homepage": "https://shiny.rstudio.com",
|
||||
"repository": "github:rstudio/shiny",
|
||||
"name": "@types/rstudio-shiny",
|
||||
"version": "1.7.1-alpha.9002",
|
||||
"version": "1.7.1-alpha.9003",
|
||||
"license": "GPL-3.0-only",
|
||||
"main": "",
|
||||
"browser": "",
|
||||
@@ -46,7 +46,8 @@
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"autoprefixer": "^10.2.6",
|
||||
"bootstrap-datepicker": "1.9.0",
|
||||
"browserslist": "^4.16.6",
|
||||
"browserslist": "^4.19.1",
|
||||
"caniuse-lite": "^1.0.30001312",
|
||||
"core-js": "^3.13.0",
|
||||
"esbuild": "^0.12.4",
|
||||
"esbuild-plugin-babel": "https://github.com/schloerke/esbuild-plugin-babel#patch-2",
|
||||
|
||||
@@ -8,7 +8,7 @@ yarn add https://github.com/rstudio/shiny\#v1.7.0
|
||||
|
||||
, matching the GitHub tag to your current the Shiny CRAN release (ex: `v1.7.0`). If you are asked to select a version of `@types/jquery`, please select the closest matching version.
|
||||
|
||||
This will provide a global type defintion of `Shiny`, let your IDE know that `window.Shiny` is of type `Shiny`, and declare a globally available variable `Shiny` within your project. You **should not** need to import anything. Similar to `jQuery`, it should _Just Work_<sup>TM</sup>.
|
||||
This will provide a global type definition of `Shiny`, let your IDE know that `window.Shiny` is of type `Shiny`, and declare a globally available variable `Shiny` within your project. You **should not** need to import anything. Similar to `jQuery`, it should _Just Work_<sup>TM</sup>.
|
||||
|
||||
When loading your compiled file, it should be loaded after `shiny.js` is loaded. If you are using an `htmlDependency()` to add your code to the page, your script will automatically be loaded after has been loaded.
|
||||
|
||||
@@ -192,7 +192,7 @@ Both JavaScript files will produce a sourcemap (`**.js.map`) that the browser wi
|
||||
|
||||
### Exported types
|
||||
|
||||
`./extras/globalShiny.ts` contains global declarations to define `window.Shiny`, a globally available `Shiny` variable, and a globally available `Shiny` type. This file is in a parallel folder to `./src` to avoid `Shiny` from being globally accessable within the source code. However, this file is the default type defintion when the Type definitions are installed by external developers.
|
||||
`./extras/globalShiny.ts` contains global declarations to define `window.Shiny`, a globally available `Shiny` variable, and a globally available `Shiny` type. This file is in a parallel folder to `./src` to avoid `Shiny` from being globally accessable within the source code. However, this file is the default type definition when the Type definitions are installed by external developers.
|
||||
|
||||
### GitHub Actions
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import babelPlugin from "esbuild-plugin-babel";
|
||||
|
||||
build({
|
||||
bundle: true,
|
||||
sourcemap: "inline",
|
||||
sourcemap: true,
|
||||
minify: true,
|
||||
plugins: [babelPlugin()],
|
||||
banner: banner,
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
/* eslint-disable unicorn/filename-case */
|
||||
let protocol = "ws:";
|
||||
const protocol = (window.location.protocol === "https:") ? "wss:" : "ws:";
|
||||
// Add trailing slash to path, if necessary, before appending "autoreload"
|
||||
const defaultPath = window.location.pathname.replace(/\/?$/, "/") + "autoreload/";
|
||||
const defaultUrl = `${protocol}//${window.location.host}${defaultPath}`;
|
||||
|
||||
if (window.location.protocol === "https:") protocol = "wss:";
|
||||
|
||||
let defaultPath = window.location.pathname;
|
||||
|
||||
if (!/\/$/.test(defaultPath)) defaultPath += "/";
|
||||
defaultPath += "autoreload/";
|
||||
|
||||
const ws = new WebSocket(protocol + "//" + window.location.host + defaultPath);
|
||||
// By default, use the defaultUrl. But if there's a data-ws-url attribute on our
|
||||
// <script> tag, use that instead.
|
||||
const wsUrl = document.currentScript.dataset.wsUrl || defaultUrl;
|
||||
const ws = new WebSocket(wsUrl);
|
||||
|
||||
ws.onmessage = function (event) {
|
||||
if (event.data === "autoreload") {
|
||||
|
||||
@@ -22,7 +22,7 @@ class InputBinding {
|
||||
return false;
|
||||
el;
|
||||
}
|
||||
getValue(el: HTMLElement): unknown {
|
||||
getValue(el: HTMLElement): any {
|
||||
throw "Not implemented";
|
||||
el; // unused var
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import type { ErrorsMessageValue } from "../shiny/shinyapp";
|
||||
interface ShinyEventCommon extends JQuery.Event {
|
||||
name: string;
|
||||
value: unknown;
|
||||
el: HTMLElement;
|
||||
el: HTMLElement | null;
|
||||
}
|
||||
interface ShinyEventInputChanged extends ShinyEventCommon {
|
||||
value: unknown;
|
||||
binding: InputBinding;
|
||||
binding: InputBinding | null;
|
||||
inputType: string;
|
||||
priority: EventPriority;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ function createClickInfo(
|
||||
mousedown: (e: JQuery.MouseDownEvent) => void;
|
||||
dblclickIE8: (e: JQuery.DoubleClickEvent) => void;
|
||||
} {
|
||||
let clickTimer = null;
|
||||
let clickTimer: ReturnType<typeof setTimeout> = null;
|
||||
let pendingE: JQuery.MouseDownEvent = null; // A pending mousedown2 event
|
||||
|
||||
// Create a new event of type eventType (like 'mousedown2'), and trigger
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { BoundsCss, Bounds, BrushOpts } from "./createBrush";
|
||||
import type { Offset } from "./findbox";
|
||||
import type { Coordmap } from "./initCoordmap";
|
||||
import type { Panel } from "./initPanelScales";
|
||||
import type { InputRatePolicy } from "../inputPolicies";
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Handler creators for click, hover, brush.
|
||||
@@ -83,7 +84,7 @@ function createHoverHandler(
|
||||
nullOutside
|
||||
);
|
||||
|
||||
let hoverInfoSender: Debouncer | Throttler;
|
||||
let hoverInfoSender: InputRatePolicy<typeof sendHoverInfo>;
|
||||
|
||||
if (delayType === "throttle")
|
||||
hoverInfoSender = new Throttler(null, sendHoverInfo, delay);
|
||||
|
||||
@@ -118,7 +118,7 @@ type Coordmap = {
|
||||
inputId: string,
|
||||
clip?: boolean,
|
||||
nullOutside?: boolean
|
||||
) => (e: JQuery.MouseDownEvent) => void;
|
||||
) => (e: JQuery.MouseDownEvent | JQuery.MouseMoveEvent) => void;
|
||||
};
|
||||
|
||||
// This adds functions to the coordmap object to handle various
|
||||
|
||||
@@ -5,8 +5,9 @@ import { InputRateDecorator } from "./inputRateDecorator";
|
||||
import { InputDeferDecorator } from "./inputDeferDecorator";
|
||||
import { InputValidateDecorator } from "./inputValidateDecorator";
|
||||
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy } from "./inputPolicy";
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import type { InputRatePolicy } from "./inputRatePolicy";
|
||||
|
||||
export {
|
||||
InputBatchSender,
|
||||
@@ -15,7 +16,6 @@ export {
|
||||
InputRateDecorator,
|
||||
InputDeferDecorator,
|
||||
InputValidateDecorator,
|
||||
InputPolicy,
|
||||
};
|
||||
|
||||
export type { EventPriority };
|
||||
export type { InputPolicy, EventPriority, InputRatePolicy };
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
import $ from "jquery";
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
import type { ShinyApp } from "../shiny/shinyapp";
|
||||
|
||||
// Schedules data to be sent to shinyapp at the next setTimeout(0).
|
||||
// Batches multiple input calls into one websocket message.
|
||||
class InputBatchSender extends InputPolicy {
|
||||
class InputBatchSender implements InputPolicy {
|
||||
target!: InputPolicy; // We need this field to satisfy the InputPolicy interface
|
||||
shinyapp: ShinyApp;
|
||||
timerId: NodeJS.Timeout = null;
|
||||
timerId: ReturnType<typeof setTimeout> | null = null;
|
||||
pendingData: { [key: string]: unknown } = {};
|
||||
reentrant = false;
|
||||
lastChanceCallback: Array<() => void> = [];
|
||||
|
||||
constructor(shinyapp: ShinyApp) {
|
||||
super();
|
||||
this.shinyapp = shinyapp;
|
||||
}
|
||||
|
||||
setInput(
|
||||
nameType: string,
|
||||
value: unknown,
|
||||
opts: { priority: EventPriority }
|
||||
): void {
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void {
|
||||
this.pendingData[nameType] = value;
|
||||
|
||||
if (!this.reentrant) {
|
||||
@@ -41,9 +35,7 @@ class InputBatchSender extends InputPolicy {
|
||||
this.reentrant = true;
|
||||
try {
|
||||
this.timerId = null;
|
||||
$.each(this.lastChanceCallback, (i, callback) => {
|
||||
callback();
|
||||
});
|
||||
this.lastChanceCallback.forEach((callback) => callback());
|
||||
const currentData = this.pendingData;
|
||||
|
||||
this.pendingData = {};
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
import { hasOwnProperty } from "../utils";
|
||||
|
||||
class InputDeferDecorator extends InputPolicy {
|
||||
class InputDeferDecorator implements InputPolicy {
|
||||
pendingInput: {
|
||||
[key: string]: { value: unknown; opts: { priority: EventPriority } };
|
||||
} = {};
|
||||
target: InputPolicy;
|
||||
|
||||
constructor(target: InputPolicy) {
|
||||
super();
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
setInput(
|
||||
nameType: string,
|
||||
value: unknown,
|
||||
opts: { priority: EventPriority }
|
||||
): void {
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void {
|
||||
if (/^\./.test(nameType)) this.target.setInput(nameType, value, opts);
|
||||
else this.pendingInput[nameType] = { value, opts };
|
||||
}
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
import $ from "jquery";
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputBinding } from "../bindings";
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
import type { ShinyEventInputChanged } from "../events/shinyEvents";
|
||||
import { splitInputNameType } from "./splitInputNameType";
|
||||
|
||||
class InputEventDecorator extends InputPolicy {
|
||||
class InputEventDecorator implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
|
||||
constructor(target: InputPolicy) {
|
||||
super();
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
setInput(
|
||||
nameType: string,
|
||||
value: unknown,
|
||||
opts: {
|
||||
el: HTMLElement;
|
||||
priority: EventPriority;
|
||||
binding: InputBinding;
|
||||
}
|
||||
): void {
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void {
|
||||
const evt = jQuery.Event("shiny:inputchanged") as ShinyEventInputChanged;
|
||||
|
||||
const input = splitInputNameType(nameType);
|
||||
@@ -27,11 +18,15 @@ class InputEventDecorator extends InputPolicy {
|
||||
evt.name = input.name;
|
||||
evt.inputType = input.inputType;
|
||||
evt.value = value;
|
||||
evt.binding = opts.binding;
|
||||
evt.el = opts.el;
|
||||
evt.binding = opts.binding || null;
|
||||
evt.el = opts.el || null;
|
||||
evt.priority = opts.priority;
|
||||
|
||||
$(opts.el).trigger(evt);
|
||||
// The `shiny:inputchanged` JavaScript event now triggers on the related
|
||||
// input element instead of `document`. Existing event listeners bound to
|
||||
// `document` will still detect the event due to event bubbling. #2446
|
||||
// If no `el` exists, use `document` instead. #3584
|
||||
$(opts.el || window.document).trigger(evt);
|
||||
|
||||
if (!evt.isDefaultPrevented()) {
|
||||
let name = evt.name;
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
import { hasOwnProperty } from "../utils";
|
||||
import { splitInputNameType } from "./splitInputNameType";
|
||||
|
||||
type LastSentValues = { [key: string]: { [key: string]: string } };
|
||||
|
||||
class InputNoResendDecorator extends InputPolicy {
|
||||
lastSentValues: LastSentValues;
|
||||
class InputNoResendDecorator implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
lastSentValues: LastSentValues = {};
|
||||
|
||||
constructor(target: InputPolicy, initialValues: LastSentValues = {}) {
|
||||
super();
|
||||
this.target = target;
|
||||
this.reset(initialValues);
|
||||
}
|
||||
|
||||
setInput(
|
||||
nameType: string,
|
||||
value: unknown,
|
||||
opts: { priority: EventPriority }
|
||||
): void {
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void {
|
||||
const { name: inputName, inputType: inputType } =
|
||||
splitInputNameType(nameType);
|
||||
const jsonValue = JSON.stringify(value);
|
||||
@@ -34,13 +29,15 @@ class InputNoResendDecorator extends InputPolicy {
|
||||
this.lastSentValues[inputName] = { jsonValue, inputType };
|
||||
this.target.setInput(nameType, value, opts);
|
||||
}
|
||||
reset(values = {}): void {
|
||||
reset(values: LastSentValues = {}): void {
|
||||
// Given an object with flat name-value format:
|
||||
// { x: "abc", "y.shiny.number": 123 }
|
||||
// Create an object in cache format and save it:
|
||||
// { x: { jsonValue: '"abc"', inputType: "" },
|
||||
// y: { jsonValue: "123", inputType: "shiny.number" } }
|
||||
const cacheValues = {};
|
||||
const cacheValues: {
|
||||
[key: string]: { jsonValue: string; inputType: string };
|
||||
} = {};
|
||||
|
||||
for (const inputName in values) {
|
||||
if (hasOwnProperty(values, inputName)) {
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import type { InputBinding } from "../bindings";
|
||||
|
||||
type EventPriority = "deferred" | "event" | "immediate";
|
||||
|
||||
type InputPolicyOpts = {
|
||||
priority: EventPriority;
|
||||
el?: HTMLElement;
|
||||
binding?: InputBinding;
|
||||
};
|
||||
|
||||
// Schedules data to be sent to shinyapp at the next setTimeout(0).
|
||||
// Batches multiple input calls into one websocket message.
|
||||
class InputPolicy {
|
||||
interface InputPolicy {
|
||||
target: InputPolicy;
|
||||
|
||||
setInput(
|
||||
name: string,
|
||||
value: unknown,
|
||||
opts: { priority: EventPriority }
|
||||
): void {
|
||||
throw "not implemented";
|
||||
name;
|
||||
value;
|
||||
opts;
|
||||
}
|
||||
setInput(name: string, value: unknown, opts: InputPolicyOpts): void;
|
||||
}
|
||||
|
||||
export { InputPolicy };
|
||||
export type { EventPriority };
|
||||
export type { InputPolicy, EventPriority, InputPolicyOpts };
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
import { Debouncer, Invoker, Throttler } from "../time";
|
||||
import { splitInputNameType } from "./splitInputNameType";
|
||||
import type { InputRatePolicy } from "./inputRatePolicy";
|
||||
|
||||
type RatePolicyModes = "debounce" | "direct" | "throttle";
|
||||
class InputRateDecorator extends InputPolicy {
|
||||
inputRatePolicies = {};
|
||||
|
||||
class InputRateDecorator implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
inputRatePolicies: {
|
||||
[key: string]: InputRatePolicy<InputRateDecorator["_doSetInput"]>;
|
||||
} = {};
|
||||
|
||||
constructor(target: InputPolicy) {
|
||||
super();
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@@ -18,11 +21,7 @@ class InputRateDecorator extends InputPolicy {
|
||||
// However, $ensureInit() and $doSetInput() are meant to be passed just
|
||||
// the input name (i.e., inputId), which is why we distinguish between
|
||||
// nameType and name.
|
||||
setInput(
|
||||
nameType: string,
|
||||
value: unknown,
|
||||
opts: { priority: EventPriority }
|
||||
): void {
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void {
|
||||
const { name: inputName } = splitInputNameType(nameType);
|
||||
|
||||
this._ensureInit(inputName);
|
||||
@@ -60,7 +59,7 @@ class InputRateDecorator extends InputPolicy {
|
||||
private _doSetInput(
|
||||
nameType: string,
|
||||
value: unknown,
|
||||
opts: { priority: EventPriority }
|
||||
opts: InputPolicyOpts
|
||||
): void {
|
||||
this.target.setInput(nameType, value, opts);
|
||||
}
|
||||
|
||||
12
srcts/src/inputPolicies/inputRatePolicy.ts
Normal file
12
srcts/src/inputPolicies/inputRatePolicy.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { AnyVoidFunction } from "../utils/extraTypes";
|
||||
import type { InputPolicy } from "./inputPolicy";
|
||||
|
||||
interface InputRatePolicy<X extends AnyVoidFunction> {
|
||||
target: InputPolicy;
|
||||
func: X;
|
||||
|
||||
normalCall(...args: Parameters<X>): void;
|
||||
immediateCall(...args: Parameters<X>): void;
|
||||
}
|
||||
|
||||
export type { InputRatePolicy };
|
||||
@@ -1,61 +1,43 @@
|
||||
import $ from "jquery";
|
||||
import type { EventPriority, InputPolicy } from "./inputPolicy";
|
||||
|
||||
type MaybeInputOpts = {
|
||||
priority?: EventPriority;
|
||||
binding?: unknown;
|
||||
el?: HTMLElement;
|
||||
};
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
|
||||
// Merge opts with defaults, and return a new object.
|
||||
function addDefaultInputOpts<T>(opts?: MaybeInputOpts & T): T & {
|
||||
priority: EventPriority;
|
||||
binding: unknown;
|
||||
el?: HTMLElement;
|
||||
} {
|
||||
const newOpts = $.extend(
|
||||
{
|
||||
priority: "immediate",
|
||||
binding: null,
|
||||
el: null,
|
||||
},
|
||||
opts
|
||||
);
|
||||
function addDefaultInputOpts(opts: Partial<InputPolicyOpts>): InputPolicyOpts {
|
||||
const newOpts: InputPolicyOpts = {
|
||||
priority: "immediate",
|
||||
...opts,
|
||||
};
|
||||
|
||||
if (newOpts && typeof newOpts.priority !== "undefined") {
|
||||
switch (newOpts.priority) {
|
||||
case "deferred":
|
||||
case "immediate":
|
||||
case "event":
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
"Unexpected input value mode: '" + newOpts.priority + "'"
|
||||
);
|
||||
}
|
||||
switch (newOpts.priority) {
|
||||
case "deferred":
|
||||
case "immediate":
|
||||
case "event":
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
"Unexpected input value mode: '" + newOpts.priority + "'"
|
||||
);
|
||||
}
|
||||
|
||||
return newOpts;
|
||||
}
|
||||
|
||||
class InputValidateDecorator {
|
||||
target;
|
||||
|
||||
class InputValidateDecorator implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
constructor(target: InputPolicy) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
setInput = function <T>(
|
||||
setInput(
|
||||
nameType: string,
|
||||
value: unknown,
|
||||
opts?: MaybeInputOpts & T
|
||||
opts: Partial<InputPolicyOpts> = {}
|
||||
): void {
|
||||
if (!nameType) throw "Can't set input with empty name.";
|
||||
|
||||
const newOpts = addDefaultInputOpts(opts);
|
||||
|
||||
this.target.setInput(nameType, value, newOpts);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { InputValidateDecorator, addDefaultInputOpts };
|
||||
|
||||
@@ -47,7 +47,7 @@ function bindInputs(
|
||||
scope: BindScope = document.documentElement
|
||||
): {
|
||||
[key: string]: {
|
||||
value: unknown;
|
||||
value: ReturnType<InputBinding["getValue"]>;
|
||||
opts: { immediate: boolean; binding: InputBinding; el: HTMLElement };
|
||||
};
|
||||
} {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
InputRateDecorator,
|
||||
InputValidateDecorator,
|
||||
} from "../inputPolicies";
|
||||
import type { EventPriority } from "../inputPolicies";
|
||||
import type { InputPolicy } from "../inputPolicies";
|
||||
import { addDefaultInputOpts } from "../inputPolicies/inputValidateDecorator";
|
||||
import { debounce, Debouncer } from "../time";
|
||||
import {
|
||||
@@ -25,6 +25,7 @@ import { registerDependency } from "./render";
|
||||
import { sendImageSizeFns } from "./sendImageSize";
|
||||
import { ShinyApp } from "./shinyapp";
|
||||
import { registerNames as singletonsRegisterNames } from "./singletons";
|
||||
import type { InputPolicyOpts } from "../inputPolicies/inputPolicy";
|
||||
|
||||
// "init_shiny.js"
|
||||
function initShiny(windowShiny: Shiny): void {
|
||||
@@ -39,7 +40,7 @@ function initShiny(windowShiny: Shiny): void {
|
||||
const inputsRate = new InputRateDecorator(inputsEvent);
|
||||
const inputsDefer = new InputDeferDecorator(inputsEvent);
|
||||
|
||||
let target;
|
||||
let target: InputPolicy;
|
||||
|
||||
if ($('input[type="submit"], button[type="submit"]').length > 0) {
|
||||
// If there is a submit button on the page, use defer decorator
|
||||
@@ -61,7 +62,7 @@ function initShiny(windowShiny: Shiny): void {
|
||||
windowShiny.setInputValue = windowShiny.onInputChange = function (
|
||||
name: string,
|
||||
value: unknown,
|
||||
opts?: { priority?: EventPriority }
|
||||
opts: Partial<InputPolicyOpts> = {}
|
||||
): void {
|
||||
const newOpts = addDefaultInputOpts(opts);
|
||||
|
||||
|
||||
@@ -155,7 +155,8 @@ function addRemovalCallback(id, delay) {
|
||||
// Clear a removal callback from a notification, if present.
|
||||
function clearRemovalCallback(id) {
|
||||
const $notification = get(id);
|
||||
const oldRemovalCallback = $notification.data("removalCallback");
|
||||
const oldRemovalCallback: ReturnType<typeof setTimeout> =
|
||||
$notification.data("removalCallback");
|
||||
|
||||
if (oldRemovalCallback) {
|
||||
clearTimeout(oldRemovalCallback);
|
||||
|
||||
@@ -10,7 +10,7 @@ class SendImageSize {
|
||||
setImageSend(
|
||||
inputBatchSender: InputBatchSender,
|
||||
doSendImageSize: () => void
|
||||
): Debouncer {
|
||||
): Debouncer<typeof doSendImageSize> {
|
||||
const sendImageSizeDebouncer = new Debouncer(null, doSendImageSize, 0);
|
||||
|
||||
this.regular = function () {
|
||||
|
||||
@@ -160,7 +160,7 @@ class ShinyApp {
|
||||
return !!this.$socket;
|
||||
}
|
||||
|
||||
private scheduledReconnect = null;
|
||||
private scheduledReconnect: ReturnType<typeof setTimeout> = null;
|
||||
|
||||
reconnect(): void {
|
||||
// This function can be invoked directly even if there's a scheduled
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import $ from "jquery";
|
||||
import { toLowerCase } from "../utils";
|
||||
import type { BindScope } from "./bind";
|
||||
|
||||
const reSingleton = /<!--(SHINY.SINGLETON\[([\w]+)\])-->([\s\S]*?)<!--\/\1-->/;
|
||||
@@ -23,21 +22,30 @@ function renderHtml(
|
||||
|
||||
addToHead(processed.head);
|
||||
register(processed.singletons);
|
||||
if (where === "replace") {
|
||||
$(el).html(processed.html);
|
||||
} else {
|
||||
let elElements: HTMLElement[];
|
||||
|
||||
if (el instanceof HTMLElement) {
|
||||
elElements = [el];
|
||||
} else {
|
||||
elElements = el.toArray();
|
||||
}
|
||||
$.each(elElements, (i, el) => {
|
||||
// type InsertPosition = "beforebegin" | "afterbegin" | "beforeend" | "afterend"
|
||||
el.insertAdjacentHTML(toLowerCase(where), processed.html);
|
||||
});
|
||||
// N.B. even though the DOM insertion below _could_ be done with vanilla JS,
|
||||
// we intentionally use jQuery so that <script> tags execute.
|
||||
// https://github.com/rstudio/shiny/pull/3630
|
||||
switch (where.toLowerCase()) {
|
||||
case "replace":
|
||||
$(el).html(processed.html);
|
||||
break;
|
||||
case "beforebegin":
|
||||
$(el).before(processed.html);
|
||||
break;
|
||||
case "afterbegin":
|
||||
$(el).prepend(processed.html);
|
||||
break;
|
||||
case "beforeend":
|
||||
$(el).append(processed.html);
|
||||
break;
|
||||
case "afterend":
|
||||
$(el).after(processed.html);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unknown where position: " + where);
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
// Take an object where keys are names of singletons, and merges it into
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
class Debouncer {
|
||||
target: unknown;
|
||||
func: (...args: unknown[]) => void;
|
||||
delayMs: number;
|
||||
timerId: NodeJS.Timeout;
|
||||
args: unknown[];
|
||||
import type { InputPolicy } from "../inputPolicies";
|
||||
import type { InputRatePolicy } from "../inputPolicies/inputRatePolicy";
|
||||
import type { AnyVoidFunction } from "../utils/extraTypes";
|
||||
|
||||
constructor(
|
||||
target: unknown,
|
||||
func: (...args: unknown[]) => void,
|
||||
delayMs: number
|
||||
) {
|
||||
class Debouncer<X extends AnyVoidFunction> implements InputRatePolicy<X> {
|
||||
target: InputPolicy;
|
||||
func: X;
|
||||
delayMs: number | undefined;
|
||||
timerId: ReturnType<typeof setTimeout> | null;
|
||||
args: Parameters<X> | null;
|
||||
|
||||
constructor(target: InputPolicy, func: X, delayMs: number | undefined) {
|
||||
this.target = target;
|
||||
this.func = func;
|
||||
this.delayMs = delayMs;
|
||||
@@ -18,7 +18,7 @@ class Debouncer {
|
||||
this.args = null;
|
||||
}
|
||||
|
||||
normalCall(...args: unknown[]): void {
|
||||
normalCall(...args: Parameters<X>): void {
|
||||
this.$clearTimer();
|
||||
this.args = args;
|
||||
|
||||
@@ -30,7 +30,7 @@ class Debouncer {
|
||||
this.$invoke();
|
||||
}, this.delayMs);
|
||||
}
|
||||
immediateCall(...args: unknown[]): void {
|
||||
immediateCall(...args: Parameters<X>): void {
|
||||
this.$clearTimer();
|
||||
this.args = args;
|
||||
this.$invoke();
|
||||
@@ -45,7 +45,11 @@ class Debouncer {
|
||||
}
|
||||
}
|
||||
$invoke(): void {
|
||||
this.func.apply(this.target, this.args);
|
||||
if (this.args && this.args.length > 0) {
|
||||
this.func.apply(this.target, this.args);
|
||||
} else {
|
||||
this.func.apply(this.target);
|
||||
}
|
||||
this.args = null;
|
||||
}
|
||||
}
|
||||
@@ -62,13 +66,15 @@ class Debouncer {
|
||||
// 900ms intervals will result in a single execution
|
||||
// of the underlying function, 1000ms after the 17th
|
||||
// call.
|
||||
function debounce<T>(
|
||||
threshold: number,
|
||||
func: (...args: T[]) => void
|
||||
): (...args: T[]) => void {
|
||||
let timerId = null;
|
||||
function debounce<T extends (...args: unknown[]) => void>(
|
||||
threshold: number | undefined,
|
||||
func: T
|
||||
): (...args: Parameters<T>) => void {
|
||||
let timerId: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
return function (...args) {
|
||||
// Do not alter `function()` into an arrow function.
|
||||
// The `this` context needs to be dynamically bound
|
||||
return function thisFunc(...args: Parameters<T>) {
|
||||
if (timerId !== null) {
|
||||
clearTimeout(timerId);
|
||||
timerId = null;
|
||||
@@ -78,7 +84,8 @@ function debounce<T>(
|
||||
// check is needed
|
||||
if (timerId === null) return;
|
||||
timerId = null;
|
||||
func.apply(this, args);
|
||||
// Applying on `thisFunc` passes through the `this` context
|
||||
func.apply(thisFunc, args);
|
||||
}, threshold);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Debouncer, debounce } from "./debounce";
|
||||
import { Invoker } from "./invoke";
|
||||
import { Throttler, throttle } from "./throttle";
|
||||
import { Throttler } from "./throttle";
|
||||
|
||||
export { Debouncer, debounce, Invoker, Throttler, throttle };
|
||||
export { Debouncer, debounce, Invoker, Throttler };
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import type { InputPolicy } from "../inputPolicies";
|
||||
import type { InputRatePolicy } from "../inputPolicies/inputRatePolicy";
|
||||
import type { AnyVoidFunction } from "../utils/extraTypes";
|
||||
|
||||
class Invoker<T> {
|
||||
class Invoker<X extends AnyVoidFunction> implements InputRatePolicy<X> {
|
||||
target: InputPolicy;
|
||||
func: () => void;
|
||||
func: X;
|
||||
|
||||
constructor(target: InputPolicy, func: (...args: T[]) => void) {
|
||||
constructor(target: InputPolicy, func: X) {
|
||||
this.target = target;
|
||||
this.func = func;
|
||||
}
|
||||
|
||||
// TODO-barret - Don't know how to define the method twice and still have access to "this"
|
||||
normalCall(...args: T[]): void {
|
||||
normalCall(...args: Parameters<X>): void {
|
||||
this.func.apply(this.target, args);
|
||||
}
|
||||
immediateCall(...args: T[]): void {
|
||||
immediateCall(...args: Parameters<X>): void {
|
||||
this.func.apply(this.target, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
class Throttler<T = unknown> {
|
||||
target: unknown;
|
||||
func: (...args: T[]) => void;
|
||||
delayMs: number;
|
||||
timerId: NodeJS.Timeout;
|
||||
args: T[];
|
||||
/* eslint-disable indent */
|
||||
import type { InputPolicy } from "../inputPolicies";
|
||||
import type { InputRatePolicy } from "../inputPolicies/inputRatePolicy";
|
||||
import type { AnyVoidFunction } from "../utils/extraTypes";
|
||||
|
||||
constructor(target: unknown, func: (...args: T[]) => void, delayMs: number) {
|
||||
class Throttler<X extends AnyVoidFunction> implements InputRatePolicy<X> {
|
||||
target: InputPolicy;
|
||||
func: X;
|
||||
delayMs: number | undefined;
|
||||
timerId: ReturnType<typeof setTimeout> | null;
|
||||
args: Parameters<X> | null;
|
||||
|
||||
constructor(target: InputPolicy, func: X, delayMs: number | undefined) {
|
||||
this.target = target;
|
||||
this.func = func;
|
||||
this.delayMs = delayMs;
|
||||
@@ -14,7 +19,7 @@ class Throttler<T = unknown> {
|
||||
this.args = null;
|
||||
}
|
||||
|
||||
normalCall(...args: T[]): void {
|
||||
normalCall(...args: Parameters<X>): void {
|
||||
this.args = args;
|
||||
if (this.timerId === null) {
|
||||
this.$invoke();
|
||||
@@ -23,11 +28,11 @@ class Throttler<T = unknown> {
|
||||
// check is needed
|
||||
if (this.timerId === null) return;
|
||||
this.$clearTimer();
|
||||
if (args.length > 0) this.normalCall.apply(this, ...args);
|
||||
if (args.length > 0) this.normalCall(...args);
|
||||
}, this.delayMs);
|
||||
}
|
||||
}
|
||||
immediateCall(...args: T[]): void {
|
||||
immediateCall(...args: Parameters<X>): void {
|
||||
this.$clearTimer();
|
||||
this.args = args;
|
||||
this.$invoke();
|
||||
@@ -42,54 +47,61 @@ class Throttler<T = unknown> {
|
||||
}
|
||||
}
|
||||
$invoke(): void {
|
||||
this.func.apply(this.target, this.args);
|
||||
if (this.args && this.args.length > 0) {
|
||||
this.func.apply(this.target, this.args);
|
||||
} else {
|
||||
this.func.apply(this.target);
|
||||
}
|
||||
this.args = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a throttled version of the given function.
|
||||
// Throttling means that the underlying function will
|
||||
// be executed no more than once every `threshold`
|
||||
// milliseconds.
|
||||
//
|
||||
// For example, if a function is throttled with a
|
||||
// threshold of 1000ms, then calling it 17 times at
|
||||
// 900ms intervals will result in something like 15
|
||||
// or 16 executions of the underlying function.
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function throttle<T>(
|
||||
threshold: number,
|
||||
func: (...args: T[]) => void
|
||||
): (...args: T[]) => void {
|
||||
let executionPending = false;
|
||||
let timerId = null;
|
||||
let self, args: T[];
|
||||
// // Returns a throttled version of the given function.
|
||||
// // Throttling means that the underlying function will
|
||||
// // be executed no more than once every `threshold`
|
||||
// // milliseconds.
|
||||
// //
|
||||
// // For example, if a function is throttled with a
|
||||
// // threshold of 1000ms, then calling it 17 times at
|
||||
// // 900ms intervals will result in something like 15
|
||||
// // or 16 executions of the underlying function.
|
||||
// // eslint-disable-next-line no-unused-vars
|
||||
// function throttle<T>(
|
||||
// threshold: number,
|
||||
// func: (...args: T[]) => void
|
||||
// ): (...args: T[]) => void {
|
||||
// let executionPending = false;
|
||||
// let timerId: number | null = null;
|
||||
// let self: unknown, args: T[] | null;
|
||||
|
||||
function throttled(...argumentVals: T[]) {
|
||||
self = null;
|
||||
args = null;
|
||||
if (timerId === null) {
|
||||
// Haven't seen a call recently. Execute now and
|
||||
// start a timer to buffer any subsequent calls.
|
||||
timerId = setTimeout(function () {
|
||||
// When time expires, clear the timer; and if
|
||||
// there has been a call in the meantime, repeat.
|
||||
timerId = null;
|
||||
if (executionPending) {
|
||||
executionPending = false;
|
||||
throttled.apply(self, args);
|
||||
}
|
||||
}, threshold);
|
||||
func.apply(this, argumentVals);
|
||||
} else {
|
||||
// Something executed recently. Don't do anything
|
||||
// except set up target/arguments to be called later
|
||||
executionPending = true;
|
||||
self = this;
|
||||
args = argumentVals;
|
||||
}
|
||||
}
|
||||
return throttled;
|
||||
}
|
||||
// function throttled(...argumentVals: T[]) {
|
||||
// self = null;
|
||||
// args = null;
|
||||
// if (timerId === null) {
|
||||
// // Haven't seen a call recently. Execute now and
|
||||
// // start a timer to buffer any subsequent calls.
|
||||
// timerId = setTimeout(function () {
|
||||
// // When time expires, clear the timer; and if
|
||||
// // there has been a call in the meantime, repeat.
|
||||
// timerId = null;
|
||||
// if (executionPending) {
|
||||
// executionPending = false;
|
||||
// throttled.apply(self, args || []);
|
||||
// }
|
||||
// }, threshold);
|
||||
// func.apply(this, argumentVals);
|
||||
// } else {
|
||||
// // Something executed recently. Don't do anything
|
||||
// // except set up target/arguments to be called later
|
||||
// executionPending = true;
|
||||
// self = this as unknown;
|
||||
// args = argumentVals;
|
||||
// }
|
||||
// }
|
||||
// return throttled;
|
||||
// }
|
||||
|
||||
export { Throttler, throttle };
|
||||
export {
|
||||
Throttler,
|
||||
// throttle
|
||||
};
|
||||
|
||||
4
srcts/src/utils/extraTypes.ts
Normal file
4
srcts/src/utils/extraTypes.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
type AnyFunction = (...args: any[]) => any;
|
||||
type AnyVoidFunction = (...args: any[]) => void;
|
||||
|
||||
export type { AnyFunction, AnyVoidFunction };
|
||||
@@ -5,7 +5,7 @@ declare class InputBinding {
|
||||
find(scope: BindScope): JQuery<HTMLElement>;
|
||||
getId(el: HTMLElement): string;
|
||||
getType(el: HTMLElement): string | false;
|
||||
getValue(el: HTMLElement): unknown;
|
||||
getValue(el: HTMLElement): any;
|
||||
subscribe(el: HTMLElement, callback: (value: boolean) => void): void;
|
||||
unsubscribe(el: HTMLElement): void;
|
||||
receiveMessage(el: HTMLElement, data: unknown): void;
|
||||
|
||||
4
srcts/types/src/events/shinyEvents.d.ts
vendored
4
srcts/types/src/events/shinyEvents.d.ts
vendored
@@ -6,11 +6,11 @@ import type { ErrorsMessageValue } from "../shiny/shinyapp";
|
||||
interface ShinyEventCommon extends JQuery.Event {
|
||||
name: string;
|
||||
value: unknown;
|
||||
el: HTMLElement;
|
||||
el: HTMLElement | null;
|
||||
}
|
||||
interface ShinyEventInputChanged extends ShinyEventCommon {
|
||||
value: unknown;
|
||||
binding: InputBinding;
|
||||
binding: InputBinding | null;
|
||||
inputType: string;
|
||||
priority: EventPriority;
|
||||
}
|
||||
|
||||
2
srcts/types/src/imageutils/initCoordmap.d.ts
vendored
2
srcts/types/src/imageutils/initCoordmap.d.ts
vendored
@@ -37,7 +37,7 @@ declare type Coordmap = {
|
||||
cssToImgScalingRatio: () => Offset;
|
||||
getPanelCss: (offsetCss: OffsetCss, expand?: number) => Panel;
|
||||
isInPanelCss: (offsetCss: OffsetCss, expand?: number) => boolean;
|
||||
mouseCoordinateSender: (inputId: string, clip?: boolean, nullOutside?: boolean) => (e: JQuery.MouseDownEvent) => void;
|
||||
mouseCoordinateSender: (inputId: string, clip?: boolean, nullOutside?: boolean) => (e: JQuery.MouseDownEvent | JQuery.MouseMoveEvent) => void;
|
||||
};
|
||||
declare function initCoordmap($el: JQuery<HTMLElement>, coordmap_: CoordmapInit): Coordmap;
|
||||
export type { Coordmap, CoordmapInit };
|
||||
|
||||
7
srcts/types/src/inputPolicies/index.d.ts
vendored
7
srcts/types/src/inputPolicies/index.d.ts
vendored
@@ -4,7 +4,8 @@ import { InputEventDecorator } from "./inputEventDecorator";
|
||||
import { InputRateDecorator } from "./inputRateDecorator";
|
||||
import { InputDeferDecorator } from "./inputDeferDecorator";
|
||||
import { InputValidateDecorator } from "./inputValidateDecorator";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy } from "./inputPolicy";
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
export { InputBatchSender, InputEventDecorator, InputNoResendDecorator, InputRateDecorator, InputDeferDecorator, InputValidateDecorator, InputPolicy, };
|
||||
export type { EventPriority };
|
||||
import type { InputRatePolicy } from "./inputRatePolicy";
|
||||
export { InputBatchSender, InputEventDecorator, InputNoResendDecorator, InputRateDecorator, InputDeferDecorator, InputValidateDecorator, };
|
||||
export type { InputPolicy, EventPriority, InputRatePolicy };
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
/// <reference types="node" />
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
import type { ShinyApp } from "../shiny/shinyapp";
|
||||
declare class InputBatchSender extends InputPolicy {
|
||||
declare class InputBatchSender implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
shinyapp: ShinyApp;
|
||||
timerId: NodeJS.Timeout;
|
||||
timerId: ReturnType<typeof setTimeout> | null;
|
||||
pendingData: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
reentrant: boolean;
|
||||
lastChanceCallback: Array<() => void>;
|
||||
constructor(shinyapp: ShinyApp);
|
||||
setInput(nameType: string, value: unknown, opts: {
|
||||
priority: EventPriority;
|
||||
}): void;
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void;
|
||||
private _sendNow;
|
||||
}
|
||||
export { InputBatchSender };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
declare class InputDeferDecorator extends InputPolicy {
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
declare class InputDeferDecorator implements InputPolicy {
|
||||
pendingInput: {
|
||||
[key: string]: {
|
||||
value: unknown;
|
||||
@@ -9,10 +9,9 @@ declare class InputDeferDecorator extends InputPolicy {
|
||||
};
|
||||
};
|
||||
};
|
||||
target: InputPolicy;
|
||||
constructor(target: InputPolicy);
|
||||
setInput(nameType: string, value: unknown, opts: {
|
||||
priority: EventPriority;
|
||||
}): void;
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void;
|
||||
submit(): void;
|
||||
}
|
||||
export { InputDeferDecorator };
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputBinding } from "../bindings";
|
||||
declare class InputEventDecorator extends InputPolicy {
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
declare class InputEventDecorator implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
constructor(target: InputPolicy);
|
||||
setInput(nameType: string, value: unknown, opts: {
|
||||
el: HTMLElement;
|
||||
priority: EventPriority;
|
||||
binding: InputBinding;
|
||||
}): void;
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void;
|
||||
}
|
||||
export { InputEventDecorator };
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
declare type LastSentValues = {
|
||||
[key: string]: {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
declare class InputNoResendDecorator extends InputPolicy {
|
||||
declare class InputNoResendDecorator implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
lastSentValues: LastSentValues;
|
||||
constructor(target: InputPolicy, initialValues?: LastSentValues);
|
||||
setInput(nameType: string, value: unknown, opts: {
|
||||
priority: EventPriority;
|
||||
}): void;
|
||||
reset(values?: {}): void;
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void;
|
||||
reset(values?: LastSentValues): void;
|
||||
forget(name: string): void;
|
||||
}
|
||||
export { InputNoResendDecorator };
|
||||
|
||||
15
srcts/types/src/inputPolicies/inputPolicy.d.ts
vendored
15
srcts/types/src/inputPolicies/inputPolicy.d.ts
vendored
@@ -1,9 +1,12 @@
|
||||
import type { InputBinding } from "../bindings";
|
||||
declare type EventPriority = "deferred" | "event" | "immediate";
|
||||
declare class InputPolicy {
|
||||
declare type InputPolicyOpts = {
|
||||
priority: EventPriority;
|
||||
el?: HTMLElement;
|
||||
binding?: InputBinding;
|
||||
};
|
||||
interface InputPolicy {
|
||||
target: InputPolicy;
|
||||
setInput(name: string, value: unknown, opts: {
|
||||
priority: EventPriority;
|
||||
}): void;
|
||||
setInput(name: string, value: unknown, opts: InputPolicyOpts): void;
|
||||
}
|
||||
export { InputPolicy };
|
||||
export type { EventPriority };
|
||||
export type { InputPolicy, EventPriority, InputPolicyOpts };
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import type { EventPriority } from "./inputPolicy";
|
||||
import { InputPolicy } from "./inputPolicy";
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
import type { InputRatePolicy } from "./inputRatePolicy";
|
||||
declare type RatePolicyModes = "debounce" | "direct" | "throttle";
|
||||
declare class InputRateDecorator extends InputPolicy {
|
||||
inputRatePolicies: {};
|
||||
declare class InputRateDecorator implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
inputRatePolicies: {
|
||||
[key: string]: InputRatePolicy<InputRateDecorator["_doSetInput"]>;
|
||||
};
|
||||
constructor(target: InputPolicy);
|
||||
setInput(nameType: string, value: unknown, opts: {
|
||||
priority: EventPriority;
|
||||
}): void;
|
||||
setInput(nameType: string, value: unknown, opts: InputPolicyOpts): void;
|
||||
setRatePolicy(nameType: string, mode: RatePolicyModes, millis?: number): void;
|
||||
private _ensureInit;
|
||||
private _doSetInput;
|
||||
|
||||
9
srcts/types/src/inputPolicies/inputRatePolicy.d.ts
vendored
Normal file
9
srcts/types/src/inputPolicies/inputRatePolicy.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { AnyVoidFunction } from "../utils/extraTypes";
|
||||
import type { InputPolicy } from "./inputPolicy";
|
||||
interface InputRatePolicy<X extends AnyVoidFunction> {
|
||||
target: InputPolicy;
|
||||
func: X;
|
||||
normalCall(...args: Parameters<X>): void;
|
||||
immediateCall(...args: Parameters<X>): void;
|
||||
}
|
||||
export type { InputRatePolicy };
|
||||
@@ -1,17 +1,8 @@
|
||||
import type { EventPriority, InputPolicy } from "./inputPolicy";
|
||||
declare type MaybeInputOpts = {
|
||||
priority?: EventPriority;
|
||||
binding?: unknown;
|
||||
el?: HTMLElement;
|
||||
};
|
||||
declare function addDefaultInputOpts<T>(opts?: MaybeInputOpts & T): T & {
|
||||
priority: EventPriority;
|
||||
binding: unknown;
|
||||
el?: HTMLElement;
|
||||
};
|
||||
declare class InputValidateDecorator {
|
||||
target: any;
|
||||
import type { InputPolicy, InputPolicyOpts } from "./inputPolicy";
|
||||
declare function addDefaultInputOpts(opts: Partial<InputPolicyOpts>): InputPolicyOpts;
|
||||
declare class InputValidateDecorator implements InputPolicy {
|
||||
target: InputPolicy;
|
||||
constructor(target: InputPolicy);
|
||||
setInput: <T>(nameType: string, value: unknown, opts?: MaybeInputOpts & T) => void;
|
||||
setInput(nameType: string, value: unknown, opts?: Partial<InputPolicyOpts>): void;
|
||||
}
|
||||
export { InputValidateDecorator, addDefaultInputOpts };
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user