-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
[Bug]: Document the different behaviour of active tab and hidden tab when using Data module #1303
Comments
TL;DR: This is a consequence of our transform design that penalizes transform modules that are not reactive to Action: Do you think we can detect or mitigate it? Context: What happens here is that the data is changing, but the The app developer should either:
In the example below you can see that in the first tab the first transformers don't affect the result as it's only reactive to Screencast.from.2024-08-13.15-17-20.webmoptions(
teal.log_level = "DEBUG",
teal.show_js_log = TRUE,
# teal.bs_theme = bslib::bs_theme(version = 5),
shiny.bookmarkStore = "server"
)
devtools::load_all("teal")
my_transformers <- list(
teal_transform_module(
label = "Keep first 10 from IRIS",
ui = function(id) {
ns <- NS(id)
div(
checkboxInput(ns("check"), label = "Toggle keep only first 10 rows?"),
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
result <- reactive({
print(glue::glue("Check triggered {session$ns('id')} { input$check %||% '(null)' }"))
req(data())
if (input$check) {
within(data(), iris <- head(iris, 10))
} else {
data()
}
})
result
})
}
),
teal_transform_module(
label = "Sepal.length negative?",
ui = function(id) {
ns <- NS(id)
div(
checkboxInput(ns("check"), label = "Negative Sepal.length?"),
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
result <- reactive({
print(glue::glue("Check triggered {session$ns('id')} { input$check %||% '(null)' }"))
req(data())
if (input$check) {
within(data(), iris$Sepal.Length <- iris$Sepal.Length * -1)
} else {
data()
}
})
result
})
}
),
teal_transform_module(
label = "Keep first 6 from IRIS",
ui = function(id) {
ns <- NS(id)
div(
checkboxInput(ns("check"), label = "Toggle `head(iris)`"),
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
eventReactive(input$check, {
print(glue::glue("Check triggered {session$ns('id')} { input$check %||% '(null)' }"))
req(data())
if (input$check) {
within(data(), iris <- head(iris, 6))
} else {
data()
}
})
})
}
)
)
my_transformers_good <- append(
my_transformers[1:2],
list(
teal_transform_module(
label = "Keep first 6 from IRIS (good)",
ui = function(id) {
ns <- NS(id)
div(
checkboxInput(ns("check"), label = "Toggle `head(iris)`"),
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
eventReactive(list(input$check, data()), {
print(glue::glue("Check triggered {session$ns('id')} { input$check %||% '(null)' }"))
req(data())
if (input$check) {
within(data(), iris <- head(iris, 6))
} else {
data()
}
})
})
}
)
)
)
data <- teal_data(iris = iris)
app <- init(
data = data,
modules = modules(
example_module("Module with transformations 1", transformers = my_transformers),
example_module("Module with transformations 2", transformers = my_transformers_good)
)
)
shinyApp(app$ui, app$server) |
Adding the general conclusion we had related to this issue. |
I have a feeling that something is missing. If at least one module (first one) performs properly, then maybe we can do something to enable the same behaviour to the second one. Like:
|
@donyunardi PR is coming to resolve the root cause. @averissimo is taking care of it 💪 |
What happened?
There is a different behaviour of data flow in modules when using transform during init.
The transform module server seems to be called for every module. But, shiny can trigger
reactive
values differently based on the shown/hidden state of the module. This can causing different behaviour for the active tab and hidden tab. It would be best to showcase this in the vignette about teal data module creation.In the following example you can see that we have two
teal_modules
that are identical. However, we get a validation error in second module which is hidden and the first module works fine.sessionInfo()
No response
Relevant log output
No response
Code of Conduct
Contribution Guidelines
Security Policy
The text was updated successfully, but these errors were encountered: