-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Reduce unwanted reactivity on filter panel changes #593
Changes from 3 commits
5b322a8
89572a4
4c4b081
4c507ca
3ab89db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -42,6 +42,11 @@ FilteredDataset <- R6::R6Class( # nolint | |||||
private$dataname <- dataname | ||||||
private$keys <- keys | ||||||
private$label <- if (is.null(label)) character(0) else label | ||||||
private$reactive_call <- reactiveVal() | ||||||
|
||||||
observeEvent(self$get_call(), ignoreNULL = FALSE, { | ||||||
private$reactive_call(self$get_call()) | ||||||
}) | ||||||
|
||||||
# function executing reactive call and returning data | ||||||
private$data_filtered_fun <- function(sid = "") { | ||||||
|
@@ -53,7 +58,7 @@ FilteredDataset <- R6::R6Class( # nolint | |||||
} | ||||||
env <- new.env(parent = parent.env(globalenv())) | ||||||
env[[dataname]] <- private$dataset | ||||||
filter_call <- self$get_call(sid) | ||||||
filter_call <- private$reactive_call() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It won't work for filter-counts which has non-empty For given
Why are counts so weird?
Even more technical explaination here example app# options(teal.log_level = "TRACE", teal.show_js_log = TRUE)
library("teal.slice")
library(teal)
library(scda)
library(SummarizedExperiment)
data <- teal_data() |> within({
# MAE <- hermes::multi_assay_experiment
ADSL <- synthetic_cdisc_data("latest")$adsl
ADSL$empty <- NA
ADSL$logical1 <- FALSE
ADSL$logical <- sample(c(TRUE, FALSE), size = nrow(ADSL), replace = TRUE)
ADSL$numeric <- rnorm(nrow(ADSL))
ADSL$categorical <- sample(letters[1:10], size = nrow(ADSL), replace = TRUE)
ADSL$date <- Sys.Date() + seq_len(nrow(ADSL))
ADSL$datetime <- Sys.time() + seq_len(nrow(ADSL)) * 3600 * 12
ADSL$numeric[sample(1:nrow(ADSL), size = 10, )] <- NA
ADSL$numeric[sample(1:nrow(ADSL), size = 10, )] <- Inf
ADSL$logical[sample(1:nrow(ADSL), size = 10, )] <- NA
ADSL$date[sample(1:nrow(ADSL), size = 10, )] <- NA
ADSL$datetime[sample(1:nrow(ADSL), size = 10, )] <- NA
ADSL$categorical[sample(1:nrow(ADSL), size = 10, )] <- NA
ADTTE <- synthetic_cdisc_data("latest")$adtte
ADRS <- synthetic_cdisc_data("latest")$adrs
})
teal.data::datanames(data) <- c(
# "MAE",
"ADSL", "ADTTE", "ADRS"
)
teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[teal.data::datanames(data)]
app <- init(
data = data,
modules = list(
example_module("mod1"),
modules(
example_module("mod2")
)
),
filter = teal_slices(
teal_slice("ADSL", "numeric", id = "numeric1"),
teal_slice("ADSL", "numeric", id = "numeric2"),
module_specific = TRUE,
mapping = list(
mod1 = "numeric1",
mod2 = "numeric2"
),
count_type = "all"
)
)
runApp(app)
|
||||||
eval_expr_with_msg(filter_call, env) | ||||||
get(x = dataname, envir = env) | ||||||
} | ||||||
|
@@ -374,6 +379,7 @@ FilteredDataset <- R6::R6Class( # nolint | |||||
dataname = character(0), | ||||||
keys = character(0), | ||||||
label = character(0), | ||||||
reactive_call = NULL, # reactiveVal | ||||||
|
||||||
# Adds `FilterStates` to the `private$filter_states`. | ||||||
# `FilterStates` is added once for each element of the dataset. | ||||||
|
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.
this is constructor - it should be outside of a reactive context. It is only because
srv_teal
insertUI
which is wrong and will be removed sooner or later.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.
Reverted that change 👍🏽
I was surprised that observing outside a module server worked just fine. Right now the observer is inside the
srv_active
which is also not correct. It should be somewhere similar to the global server init. I will try to move this to some server logic in theFilterData
class.But, this adds a new problem. The dataset is only dependant on the
private$reactive_call ()
which needs shiny to work. So, we have some unit tests failing. As, those tests used to be reactive on theself$get_call()
before.