Skip to content

Commit 03acb6a

Browse files
authored
Prevent too early evaluation (#1425)
Language arguments in module$server_args and module$ui_args are used in do.call. `quote = TRUE` prevents `do.call` evaluate language objects.
1 parent 75198f8 commit 03acb6a

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

R/module_nested_tabs.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
108108
class = "teal_validated",
109109
ui_check_module_datanames(ns("validate_datanames"))
110110
),
111-
do.call(modules$ui, args)
111+
do.call(what = modules$ui, args = args, quote = TRUE)
112112
)
113113
)
114114

@@ -341,9 +341,9 @@ srv_teal_module.teal_module <- function(id,
341341
}
342342

343343
if (is_arg_used(modules$server, "id")) {
344-
do.call(modules$server, args)
344+
do.call(what = modules$server, args = args, quote = TRUE)
345345
} else {
346-
do.call(callModule, c(args, list(module = modules$server)))
346+
do.call(what = callModule, args = c(args, list(module = modules$server)), quote = TRUE)
347347
}
348348
}
349349

tests/testthat/test-module_teal.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,37 @@ testthat::describe("srv_teal teal_modules", {
10351035
)
10361036
})
10371037

1038+
testthat::it("srv_teal_module.teal_module passes quoted arguments to the teal_module$server call", {
1039+
tm_query <- function(query) {
1040+
module(
1041+
"module_1",
1042+
server = function(id, data, query) {
1043+
moduleServer(id, function(input, output, session) {
1044+
reactive(q <- eval_code(data(), query))
1045+
})
1046+
},
1047+
server_args = list(query = query)
1048+
)
1049+
}
1050+
shiny::testServer(
1051+
app = srv_teal,
1052+
args = list(
1053+
id = "test",
1054+
data = teal.data::teal_data(a_dataset = iris),
1055+
modules = modules(tm_query(quote(a_dataset <- subset(a_dataset, Species == "setosa"))))
1056+
),
1057+
expr = {
1058+
session$setInputs(`teal_modules-active_tab` = "module_1")
1059+
session$flushReact()
1060+
1061+
testthat::expect_setequal(
1062+
"setosa",
1063+
unique(modules_output$module_1()()[["a_dataset"]]$Species)
1064+
)
1065+
}
1066+
)
1067+
})
1068+
10381069
testthat::it("srv_teal_module.teal_module passes filter_panel_api if specified", {
10391070
shiny::testServer(
10401071
app = srv_teal,

0 commit comments

Comments
 (0)