From 6aa6ab42f1638bc8b99082abbb487101b8ab17ff Mon Sep 17 00:00:00 2001 From: jcheng5 Date: Wed, 24 Apr 2024 17:10:15 +0000 Subject: [PATCH] `devtools::document()` (GitHub Actions) --- DESCRIPTION | 2 +- man/displayCodeModal.Rd | 7 +++-- man/expandChain.Rd | 66 +++++++++++++++++++++++++++-------------- man/outputCodeButton.Rd | 2 +- 4 files changed, 51 insertions(+), 26 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 63ab5b8..28d5ada 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,7 @@ Imports: styler, utils Encoding: UTF-8 -RoxygenNote: 7.1.2 +RoxygenNote: 7.3.1 Suggests: knitr, stringr, diff --git a/man/displayCodeModal.Rd b/man/displayCodeModal.Rd index 431e95c..d8df90c 100644 --- a/man/displayCodeModal.Rd +++ b/man/displayCodeModal.Rd @@ -27,13 +27,16 @@ If you wish to not have an icon, specify \code{clip = NULL}.} \item{footer}{UI for footer. Use \code{NULL} for no footer.} \item{size}{One of \code{"s"} for small, \code{"m"} (the default) for medium, -or \code{"l"} for large.} +\code{"l"} for large, or \code{"xl"} for extra large. Note that \code{"xl"} only +works with Bootstrap 4 and above (to opt-in to Bootstrap 4+, +pass \code{\link[bslib:bs_theme]{bslib::bs_theme()}} to the \code{theme} argument of a page container +like \code{\link[shiny:fluidPage]{fluidPage()}}).} \item{easyClose}{If \code{TRUE}, the modal dialog can be dismissed by clicking outside the dialog box, or be pressing the Escape key. If \code{FALSE} (the default), the modal dialog can't be dismissed in those ways; instead it must be dismissed by clicking on a \code{modalButton()}, or -from a call to \code{\link[shiny:showModal]{removeModal()}} on the server.} +from a call to \code{\link[shiny:removeModal]{removeModal()}} on the server.} \item{fade}{If \code{FALSE}, the modal dialog will have no fade-in animation (it will simply appear rather than fade in to view).} diff --git a/man/expandChain.Rd b/man/expandChain.Rd index d86ce97..07501a6 100644 --- a/man/expandChain.Rd +++ b/man/expandChain.Rd @@ -40,19 +40,25 @@ There are two ways to extract code from meta objects (i.e. \code{\link[=metaReac The simplest is \code{withMetaMode(obj())}, which crawls the tree of meta-reactive dependencies and expands each \code{..()} in place. -For example, consider these meta objects:\preformatted{ nums <- metaReactive(\{ runif(100) \}) +For example, consider these meta objects: + +\if{html}{\out{
}}\preformatted{ nums <- metaReactive(\{ runif(100) \}) obs <- metaObserve(\{ summary(..(nums())) hist(..(nums())) \}) -} +}\if{html}{\out{
}} -When code is extracted using \code{withMetaMode}:\preformatted{ withMetaMode(obs()) -} +When code is extracted using \code{withMetaMode}: -The result looks like this:\preformatted{ summary(runif(100)) +\if{html}{\out{
}}\preformatted{ withMetaMode(obs()) +}\if{html}{\out{
}} + +The result looks like this: + +\if{html}{\out{
}}\preformatted{ summary(runif(100)) plot(runif(100)) -} +}\if{html}{\out{
}} Notice how \code{runif(100)} is inlined wherever \code{..(nums())} appears, which is not desirable if we wish to reuse the same @@ -61,29 +67,37 @@ values for \code{summary()} and \code{plot()}. The \code{expandChain} function helps us workaround this issue by assigning return values of \code{metaReactive()} expressions to a name, then replaces relevant expansion (e.g., \code{..(nums())}) -with the appropriate name (e.g. \code{nums}).\preformatted{ expandChain(obs()) -} +with the appropriate name (e.g. \code{nums}). + +\if{html}{\out{
}}\preformatted{ expandChain(obs()) +}\if{html}{\out{
}} + +The result looks like this: -The result looks like this:\preformatted{ nums <- runif(100) +\if{html}{\out{
}}\preformatted{ nums <- runif(100) summary(nums) plot(nums) -} +}\if{html}{\out{
}} + +You can pass multiple meta objects and/or comments to \code{expandChain}. -You can pass multiple meta objects and/or comments to \code{expandChain}.\preformatted{ expandChain( +\if{html}{\out{
}}\preformatted{ expandChain( "# Generate values", nums(), "# Summarize and plot", obs() ) -} +}\if{html}{\out{
}} + +Output: -Output:\preformatted{ # Load data +\if{html}{\out{
}}\preformatted{ # Load data nums <- runif(100) nums # Inspect data summary(nums) plot(nums) -} +}\if{html}{\out{
}} You can suppress the printing of the \code{nums} vector in the previous example by wrapping the \code{nums()} argument to \code{expandChain()} with \code{invisible(nums())}. @@ -104,14 +118,16 @@ up with duplicated code. To remove this duplication, we need the second call. We can achieve this by creating an "expansion context" and sharing it between -the two calls.\preformatted{ exp_ctx <- newExpansionContext() +the two calls. + +\if{html}{\out{
}}\preformatted{ exp_ctx <- newExpansionContext() chunk1 <- expandChain(.expansionContext = exp_ctx, invisible(nums()) ) chunk2 <- expandChain(.expansionContext = exp_ctx, obs() ) -} +}\if{html}{\out{
}} After this code is run, \code{chunk1} contains only the definition of \code{nums} and \code{chunk2} contains only the code for \code{obs}. @@ -122,31 +138,37 @@ After this code is run, \code{chunk1} contains only the definition of \code{nums Sometimes, when generating code, we want to completely replace the implementation of a \code{metaReactive}. For example, our Shiny app might contain -this logic, using \code{\link[shiny:fileInput]{shiny::fileInput()}}:\preformatted{ data <- metaReactive2(\{ +this logic, using \code{\link[shiny:fileInput]{shiny::fileInput()}}: + +\if{html}{\out{
}}\preformatted{ data <- metaReactive2(\{ req(input$file_upload) metaExpr(read.csv(..(input$file_upload$datapath))) \}) obs <- metaObserve(\{ summary(..(data())) \}) -} +}\if{html}{\out{
}} Shiny's file input works by saving uploading files to a temp directory. The file referred to by \code{input$file_upload$datapath} won't be available when another user tries to run the generated code. You can use the expansion context object to swap out the implementation of -\code{data}, or any other \code{metaReactive}:\preformatted{ ec <- newExpansionContext() +\code{data}, or any other \code{metaReactive}: + +\if{html}{\out{
}}\preformatted{ ec <- newExpansionContext() ec$substituteMetaReactive(data, function() \{ metaExpr(read.csv("data.csv")) \}) expandChain(.expansionContext = ec, obs()) -} +}\if{html}{\out{
}} -Result:\preformatted{ data <- read.csv("data.csv") +Result: + +\if{html}{\out{
}}\preformatted{ data <- read.csv("data.csv") summary(data) -} +}\if{html}{\out{
}} Just make sure this code ends up in a script or Rmd bundle that includes the uploaded file as \code{data.csv}, and the user will be able to reproduce your diff --git a/man/outputCodeButton.Rd b/man/outputCodeButton.Rd index bcd7f7c..3ba56a6 100644 --- a/man/outputCodeButton.Rd +++ b/man/outputCodeButton.Rd @@ -21,7 +21,7 @@ you could also use any other HTML, like an image.} \item{icon}{An optional \code{\link[shiny:icon]{icon()}} to appear on the button.} \item{width}{The width of the input, e.g. \code{'400px'}, or \code{'100\%'}; -see \code{\link[shiny:reexports]{validateCssUnit()}}.} +see \code{\link[shiny:validateCssUnit]{validateCssUnit()}}.} \item{...}{Named attributes to be applied to the button or link.} }