-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Duplicated decorators during an edge case of named and unnamed decorators #835
Conversation
Signed-off-by: Marcin <[email protected]>
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.
I can also reproduce the CI checks failures about the vignettes.
Check the linter message and Dawid comment.
Merge branch '1316_duplicates@main' of https://github.com/insightsengineering/teal.modules.general into 1316_duplicates@main # Conflicts: # R/utils.R
Alrighty, for now I allowed only to pass either all named, or all unnamed decorators Codepkgload::load_all(".")
data <- teal_data()
data <- within(data, {
require(nestcolor)
CO2 <- CO2
factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L))))
CO2[factors] <- lapply(CO2[factors], as.character)
})
static_decorator <- teal_transform_module(
label = "Static decorator",
server = function(id, data) {
moduleServer(id, function(input, output, session) {
reactive({
req(data())
within(data(), {
plot <- plot +
ggplot2::ggtitle("This is title") +
ggplot2::xlab("x axis")
})
})
})
}
)
interactive_decorator <- teal_transform_module(
label = "Interactive decorator",
ui = function(id) {
ns <- NS(id)
div(
textInput(ns("x_axis_title"), "X axis title", value = "x axis")
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
reactive({
req(data())
within(data(),
{
plot <- plot +
ggplot2::ggtitle("This is title") +
ggplot2::xlab(my_title)
},
my_title = input$x_axis_title
)
})
})
}
)
app <- init(
data = data,
modules = tm_g_bivariate(
x = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "conc",
fixed = FALSE
)
),
y = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "uptake",
multiple = FALSE,
fixed = FALSE
)
),
row_facet = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "Type",
fixed = FALSE
)
),
col_facet = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "Treatment",
fixed = FALSE
)
),
# decorators = list() # SHOULD BE OK
# decorators = list(plot = static_decorator, default = interactive_decorator) # SHOULD BE OK
# decorators = list(static_decorator, interactive_decorator) # SHOULD BE OK
# decorators = list(plot = static_decorator, interactive_decorator) # SHOULD THROWN AN ERROR
)
)
shinyApp(app$ui, app$server)
|
Unit Tests Summary 1 files 22 suites 13m 2s ⏱️ Results for commit 67d76ed. ♻️ This comment has been updated with latest results. |
Unit Test Performance Difference
Additional test case details
Results for commit 8bf03fb ♻️ This comment has been updated with latest results. |
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.
I like the decision to only allow named or unnamed decorators.
-
decorators = list()
No problem ✅
-
decorators = list(plot = static_decorator, default = interactive_decorator)
I don't see the default interactive decorator having any effect. This makes sense but there is no message that the named one will be used instead. This confused me initially. Could you add a message/warning so that users know what is happening on that case? Or alternative patch the documentation?
-
decorators = list(static_decorator, interactive_decorator)
The interactive decorator worked well, but again no notification of what happened with the static_decorator. I would prefer to have some documentation or a clear message of what is happening here.⁉️ -
decorators = list(plot = static_decorator, interactive_decorator)
Throws an error (not a warning) ✅ -
decorators = list(plot = static_decorator, plot = interactive_decorator)
This example also throws the same error "All decorators should either be named or unnamed" but here the duplicated decorator are named so the message is not informative. Could the users get a more informative message? ❌
@llrs-roche funny things.
Both of them are used, but both of them edit the same thing.
If you remove ![]() Codepkgload::load_all(".")
data <- teal_data()
data <- within(data, {
require(nestcolor)
CO2 <- CO2
factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L))))
CO2[factors] <- lapply(CO2[factors], as.character)
})
static_decorator <- teal_transform_module(
label = "Static decorator",
server = function(id, data) {
moduleServer(id, function(input, output, session) {
reactive({
req(data())
within(data(), {
plot <- plot +
ggplot2::ggtitle("This is title")
})
})
})
}
)
interactive_decorator <- teal_transform_module(
label = "Interactive decorator",
ui = function(id) {
ns <- NS(id)
div(
textInput(ns("x_axis_title"), "X axis title", value = "x axis")
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
reactive({
req(data())
within(data(),
{
plot <- plot +
ggplot2::ggtitle("This is title") +
ggplot2::xlab(my_title)
},
my_title = input$x_axis_title
)
})
})
}
)
app <- init(
data = data,
modules = tm_g_bivariate(
x = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "conc",
fixed = FALSE
)
),
y = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "uptake",
multiple = FALSE,
fixed = FALSE
)
),
row_facet = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "Type",
fixed = FALSE
)
),
col_facet = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "Treatment",
fixed = FALSE
)
),
# decorators = list() # SHOULD BE OK
# decorators = list(plot = static_decorator, default = interactive_decorator) # SHOULD BE OK
# decorators = list(static_decorator, interactive_decorator) # SHOULD BE OK
decorators = list(plot = static_decorator, default = interactive_decorator) # SHOULD THROWN A WARNING
)
)
shinyApp(app$ui, app$server)
|
I think we can work on this. Thanks for double checking |
…assert_decorators, and let it pass through normalize_decorators
Hey @llrs-roche when non-unique names are passed to decorators, function will throw a warning from Now user will see Error in tm_g_bivariate(x = data_extract_spec(dataname = "CO2", select = select_spec(label = "Select variable:", :
Assertion on 'decorators' failed: Non-unique names in decorators.
Called from: mstop("Assertion on '%s' failed: %s.", var.name, res, call. = sys.call(-2L)) I will push the same to tmc |
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.
Looks good and the corner case was handled elegantly. 👍
Companion to insightsengineering/teal.modules.clinical#1325