-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent too early evaluation #1425
base: main
Are you sure you want to change the base?
Conversation
Code Coverage Summary
Diff against main
Results for commit: 9344594 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
Unit Tests Summary 1 files 27 suites 8m 59s ⏱️ Results for commit 9344594. ♻️ This comment has been updated with latest results. |
Unit Test Performance Difference
Results for commit 907dd40 ♻️ This comment has been updated with latest results. |
I'm not that familiar with expressions, calls and languages, this seems a simple fix to the issue. But I leave the review for other that might understand better the implications of this change. I noticed that
I don't think this would help on line 344, but perhaps is something to keep in mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit: nevermind about this first sentence, rethinking it doesn't make sense for quoted arguments I think this responsibility is on the module developer. See example below that works in main
with only 1 line changing (query <- enquote(query)
I don't see any bad consequences on this change, the PR is fine and I tested with different types of native language objects.
I left a comment about adding a test for this so we don't risk a regression in the future.
pkgload::load_all("teal", export_all = FALSE)
tm_query <- function(query) {
query <- enquote(query)
module(
ui = function(id) {
ns <- NS(id)
shiny::tagList(
verbatimTextOutput(ns("out")),
verbatimTextOutput(ns("out2"))
)
},
server = function(id, data, query, yada) {
moduleServer(id, function(input, output, session) {
output$out <- renderPrint({
q <- eval_code(data(), query)
print(q)
})
})
},
server_args = list(query = query)
)
}
library(teal.code)
library(teal.data)
app <- init(
data = teal_data() |> within(a <- iris),
modules = modules(
tm_query(query = quote(a_filtered <- subset(a, a$Species == "setosa")))
)
)
runApp(app)
@@ -339,9 +339,9 @@ srv_teal_module.teal_module <- function(id, | |||
} | |||
|
|||
if (is_arg_used(modules$server, "id")) { | |||
do.call(modules$server, args) | |||
do.call(modules$server, args, quote = TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test before merging, such as:
testthat::it("srv_teal_module.teal_module accepts quoted arguments", {
tm_query <- function(query) {
module(
"module_1",
server = function(id, data, query) {
moduleServer(id, function(input, output, session) {
reactive(q <- eval_code(data(), query))
)
},
server_args = list(query = query)
)
}
shiny::testServer(
app = srv_teal,
args = list(
id = "test",
data = teal.data::teal_data(a_dataset = iris),
modules = modules(tm_query(quote(a_dataset <- subset(a_dataset, Species == "setosa"))))
),
expr = {
session$setInputs(`teal_modules-active_tab` = "module_1")
session$flushReact()
testthat::expect_setequal(
"setosa",
unique(modules_output$module_1()()[["a_dataset"]]$Species)
)
}
)
})
When
server_args
contains element being alanguage
then it is being evaluated bydo.call
. We calldo.call
when calling modules in teal. Addingquote = TRUE
to the call fixes the problem. See an example app:Alternative is to ignore this error and replace
quote()
withexpression()
asexpression
is not evaluated indo.call
.