Skip to content
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

Change name of the raw (unfiltered object) #1342

Merged
merged 13 commits into from
Sep 26, 2024
Merged
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Easier way of to call `javascript` events by setting `$(document).ready(function() { ... })`. #1114
* Provided progress bar for modules loading and data filtering during teal app startup.
* Filter mapping display has a separate icon in the tab.
* Environment of the `data` passed to the `teal_module`'s server consists unfiltered datasets contained in `.raw_data`.

# teal 0.15.2

Expand Down
8 changes: 2 additions & 6 deletions R/module_data_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ srv_data_summary <- function(id, teal_data) {

summary_table <- reactive({
req(inherits(teal_data(), "teal_data"))

if (!length(.teal_data_ls(teal_data()))) {
return(NULL)
}
Expand Down Expand Up @@ -141,16 +140,13 @@ srv_data_summary <- function(id, teal_data) {
get_filter_overview <- function(teal_data) {
datanames <- teal.data::datanames(teal_data())
joinkeys <- teal.data::join_keys(teal_data())

filtered_data_objs <- sapply(
datanames,
function(name) teal.code::get_env(teal_data())[[name]],
simplify = FALSE
)
unfiltered_data_objs <- sapply(
datanames,
function(name) teal.code::get_env(teal_data())[[paste0(name, "._raw_")]],
simplify = FALSE
)
unfiltered_data_objs <- teal.code::get_env(teal_data())[[".raw_data"]]
pawelru marked this conversation as resolved.
Show resolved Hide resolved

rows <- lapply(
datanames,
Expand Down
10 changes: 9 additions & 1 deletion R/module_filter_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active)

#' @rdname module_filter_data
.make_filtered_teal_data <- function(modules, data, datasets = NULL, datanames) {
data <- eval_code(data, sprintf("%1$s._raw_ <- %1$s", datanames))
data <- eval_code(
data,
paste0(
".raw_data <- list2env(list(",
toString(sprintf("%1$s = %1$s", datanames)),
"))\n",
"lockEnvironment(.raw_data) #@linksto .raw_data" # this is environment and it is shared by qenvs. CAN'T MODIFY!
)
)
pawelru marked this conversation as resolved.
Show resolved Hide resolved
filtered_code <- teal.slice::get_filter_expr(datasets = datasets, datanames = datanames)
filtered_teal_data <- .append_evaluated_code(data, filtered_code)
filtered_datasets <- sapply(datanames, function(x) datasets$get_data(x, filtered = TRUE), simplify = FALSE)
Expand Down
7 changes: 5 additions & 2 deletions R/module_init_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ srv_init_data <- function(id, data, modules, filter = teal_slices()) {
})

# Adds signature protection to the datanames in the data
reactive(.add_signature_to_data(data_validated()))
reactive({
req(data_validated())
.add_signature_to_data(data_validated())
})
})
}

Expand All @@ -151,7 +154,7 @@ srv_init_data <- function(id, data, modules, filter = teal_slices()) {
list(code = trimws(c(teal.code::get_code(data), hashes), which = "right")),
list(join_keys = teal.data::join_keys(data)),
sapply(
ls(teal.code::get_env(data)),
.teal_data_ls(data),
pawelru marked this conversation as resolved.
Show resolved Hide resolved
teal.code::get_var,
object = data,
simplify = FALSE
Expand Down
20 changes: 11 additions & 9 deletions R/teal_data_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ NULL
checkmate::assert_class(data, "teal_data")
checkmate::assert_class(objects, "list")
new_env <- list2env(objects, parent = .GlobalEnv)
rlang::env_coalesce(new_env, data@env)
rlang::env_coalesce(new_env, teal.code::get_env(data))
data@env <- new_env
data
}
Expand All @@ -42,35 +42,37 @@ NULL
.subset_teal_data <- function(data, datanames) {
checkmate::assert_class(data, "teal_data")
checkmate::assert_class(datanames, "character")
datanames_corrected <- intersect(datanames, ls(data@env))
dataname_corrected_with_raw <- intersect(c(datanames, sprintf("%s._raw_", datanames)), ls(data@env))

datanames_corrected <- intersect(datanames, .teal_data_ls(data))
datanames_corrected_with_raw <- c(datanames_corrected, ".raw_data")
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
if (!length(datanames)) {
return(teal_data())
}
pawelru marked this conversation as resolved.
Show resolved Hide resolved

new_data <- do.call(
teal.data::teal_data,
args = c(
mget(x = dataname_corrected_with_raw, envir = data@env),
mget(x = datanames_corrected_with_raw, envir = teal.code::get_env(data)),
list(
code = gsub(
"warning('Code was not verified for reproducibility.')\n",
"",
teal.data::get_code(data, datanames = dataname_corrected_with_raw),
teal.data::get_code(data, datanames = datanames_corrected_with_raw),
fixed = TRUE
),
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
join_keys = teal.data::join_keys(data)[datanames_corrected]
)
)
)
new_data@verified <- data@verified
teal.data::datanames(new_data) <- datanames
teal.data::datanames(new_data) <- datanames_corrected
new_data
}

#' @rdname teal_data_utilities
.teal_data_ls <- function(data) {
checkmate::assert_class(data, "teal_data")
grep("._raw_", ls(teal.code::get_env(data), all.names = FALSE), value = TRUE, invert = TRUE)
datanames <- ls(
teal.code::get_env(data),
all.names = FALSE # doesn't consider objects prefixed by `.` as datanames (including filtered datanames)
)
include_parent_datanames(datanames, teal.data::join_keys(data)) # for topological sort
}
Loading
Loading