-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into refactor
- Loading branch information
Showing
12 changed files
with
506 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Type: Package | ||
Package: teal | ||
Title: Exploratory Web Apps for Analyzing Clinical Trials Data | ||
Version: 0.14.0.9025 | ||
Date: 2023-11-28 | ||
Version: 0.14.0.9026 | ||
Date: 2023-12-05 | ||
Authors@R: c( | ||
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre")), | ||
person("Pawel", "Rucki", , "[email protected]", role = "aut"), | ||
|
@@ -40,9 +40,11 @@ Imports: | |
lifecycle (>= 0.2.0), | ||
logger (>= 0.2.0), | ||
magrittr (>= 1.5), | ||
methods, | ||
rlang (>= 1.0.0), | ||
shinyjs, | ||
stats, | ||
teal.code (>= 0.3.0.9009), | ||
teal.logger (>= 0.1.1), | ||
teal.reporter (>= 0.2.0), | ||
teal.widgets (>= 0.4.0), | ||
|
@@ -56,7 +58,6 @@ Suggests: | |
R6, | ||
rmarkdown (>= 2.19), | ||
shinyvalidate, | ||
teal.code (>= 0.3.0.9009), | ||
testthat (>= 3.1.5), | ||
withr (>= 2.1.0), | ||
yaml (>= 1.1.0) | ||
|
@@ -98,6 +99,7 @@ Collate: | |
'show_rcode_modal.R' | ||
'tdata.R' | ||
'teal.R' | ||
'teal_data_module-eval_code.R' | ||
'teal_data_module.R' | ||
'teal_reporter.R' | ||
'teal_slices-store.R' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# teal 0.14.0.9025 | ||
# teal 0.14.0.9026 | ||
|
||
### New features | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
setOldClass("teal_data_module") | ||
|
||
#' Evaluate the code in the qenv environment | ||
#' @name eval_code | ||
#' @description | ||
#' Given code is evaluated in the `qenv` environment of `teal_data` reactive defined in `teal_data_module`. | ||
#' @param object (`teal_data_module`) | ||
#' @inheritParams teal.code::eval_code | ||
#' @return Returns a `teal_data_module` object. | ||
#' @importMethodsFrom teal.code eval_code | ||
#' @importFrom methods setMethod | ||
NULL | ||
|
||
#' @rdname eval_code | ||
#' @export | ||
#' | ||
#' @examples | ||
#' tdm <- teal_data_module( | ||
#' ui = function(id) div(id = shiny::NS(id)("div_id")), | ||
#' server = function(id) { | ||
#' shiny::moduleServer(id, function(input, output, session) { | ||
#' shiny::reactive(teal_data(IRIS = iris)) | ||
#' }) | ||
#' } | ||
#' ) | ||
#' eval_code(tdm, "IRIS <- subset(IRIS, Species == 'virginica')") | ||
setMethod("eval_code", signature = c("teal_data_module", "character"), function(object, code) { | ||
teal_data_module( | ||
ui = function(id) { | ||
ns <- NS(id) | ||
object$ui(ns("mutate_inner")) | ||
}, | ||
server = function(id) { | ||
moduleServer(id, function(input, output, session) { | ||
teal_data_rv <- object$server("mutate_inner") | ||
|
||
if (!is.reactive(teal_data_rv)) { | ||
stop("The `teal_data_module` must return a reactive expression.", call. = FALSE) | ||
} | ||
|
||
td <- eventReactive(teal_data_rv(), | ||
{ | ||
if (inherits(teal_data_rv(), c("teal_data", "qenv.error"))) { | ||
eval_code(teal_data_rv(), code) | ||
} else { | ||
teal_data_rv() | ||
} | ||
}, | ||
ignoreNULL = FALSE | ||
) | ||
td | ||
}) | ||
} | ||
) | ||
}) | ||
|
||
#' @rdname eval_code | ||
#' @export | ||
setMethod("eval_code", signature = c("teal_data_module", "language"), function(object, code) { | ||
eval_code(object, code = paste(lang2calls(code), collapse = "\n")) | ||
}) | ||
|
||
#' @rdname eval_code | ||
#' @export | ||
setMethod("eval_code", signature = c("teal_data_module", "expression"), function(object, code) { | ||
eval_code(object, code = paste(lang2calls(code), collapse = "\n")) | ||
}) | ||
|
||
#' @inherit teal.code::within.qenv params title details | ||
#' @description | ||
#' Convenience function for evaluating inline code inside the environment of a | ||
#' `teal_data_module` | ||
#' | ||
#' @param data (`teal_data_module`) object | ||
#' @return Returns a `teal_data_module` object with a delayed evaluation of `expr` | ||
#' when module. | ||
#' @export | ||
#' @seealso [base::within()], [teal_data_module()] | ||
#' @examples | ||
#' tdm <- teal_data_module( | ||
#' ui = function(id) div(id = shiny::NS(id)("div_id")), | ||
#' server = function(id) { | ||
#' shiny::moduleServer(id, function(input, output, session) { | ||
#' shiny::reactive(teal_data(IRIS = iris)) | ||
#' }) | ||
#' } | ||
#' ) | ||
#' within(tdm, IRIS <- subset(IRIS, Species == "virginica")) | ||
within.teal_data_module <- function(data, expr, ...) { | ||
expr <- substitute(expr) | ||
extras <- list(...) | ||
|
||
# Add braces for consistency. | ||
if (!identical(as.list(expr)[[1L]], as.symbol("{"))) { | ||
expr <- call("{", expr) | ||
} | ||
|
||
calls <- as.list(expr)[-1] | ||
|
||
# Inject extra values into expressions. | ||
calls <- lapply(calls, function(x) do.call(substitute, list(x, env = extras))) | ||
|
||
eval_code(object = data, code = as.expression(calls)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.