Skip to content

Commit

Permalink
styling
Browse files Browse the repository at this point in the history
  • Loading branch information
zsigmas committed Oct 7, 2024
1 parent c67371d commit 7dced15
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
32 changes: 17 additions & 15 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,49 +133,51 @@ app_server_ <- function(input, output, session, opts) {
names(l) <- names(datasets_filters_info)
for (idx in seq_along(datasets_filters_info)) {
l[[idx]] <- local({
curr_dataset_filter_info <- datasets_filters_info[[idx]]
curr_dataset_filter_info <- datasets_filters_info[[idx]]
dv.filter::data_filter_server(
curr_dataset_filter_info[["id"]],
shiny::reactive({unfiltered_dataset()[[curr_dataset_filter_info[["name"]]]] %||% data.frame()})
)
curr_dataset_filter_info[["id"]],
shiny::reactive({
unfiltered_dataset()[[curr_dataset_filter_info[["name"]]]] %||% data.frame()
})
)
})
}

l
})

filtered_dataset <- shinymeta::metaReactive({
# dv.filter returns a logical vector. This contemplates the case of empty lists
filtered_dataset <- shinymeta::metaReactive({
# dv.filter returns a logical vector. This contemplates the case of empty lists
shiny::req(is.logical(global_filtered_values()))

# Depend on all datasets
purrr::walk(dataset_filters, ~.x())
purrr::walk(dataset_filters, ~ .x())

# We do not react to changed in unfiltered dataset, otherwise when a dataset changes
# We filter the previous dataset which in the best case produces and extra reactive beat
# and in the worst case produces an error in (mvbc)
# We don't want to control the error in (mvbc) because filtered dataset only changes when filter changes
ufds <- shiny::isolate(unfiltered_dataset())

curr_dataset_filters <- dataset_filters[intersect(names(dataset_filters), names(ufds))]
curr_dataset_filters <- dataset_filters[intersect(names(dataset_filters), names(ufds))]

# Current dataset must be logical with length above 0
# Check dataset filters check all datafilters are initialized
purrr::walk(curr_dataset_filters, ~shiny::req(checkmate::test_logical(.x(), min.len = 1)))
purrr::walk(curr_dataset_filters, ~ shiny::req(checkmate::test_logical(.x(), min.len = 1)))

filtered_key_values <- ufds[[filter_data]][[filter_key]][global_filtered_values()]

fds <- ufds

# Single dataset filtering
fds[names(curr_dataset_filters)] <- purrr::imap(
fds[names(curr_dataset_filters)],
function(val, nm) {
function(val, nm) {
# (mvbc)
fds[[nm]][dataset_filters[[nm]](), , drop = FALSE]
fds[[nm]][dataset_filters[[nm]](), , drop = FALSE]
}
)

# Global dataset filtering
global_filtered <- purrr::map(
fds,
Expand Down
16 changes: 8 additions & 8 deletions R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ app_ui <- function(id) {
log_inform(glue::glue("Available modules (N): {length(module_list)}"))
log_inform(glue::glue("Dataset options (N): {length(data)}"))


dataset_filters_ui <- local({
datasets_filters_info <- get_dataset_filters_info(data, filter_data)
purrr::map(
datasets_filters_info,
function(entry) {
function(entry) {
shiny::div(
id = entry[["id_cont"]],
class = "filter-control filter-filters",
shiny::tags[["label"]](entry[["name"]]),
dv.filter::data_filter_ui(ns(entry[["id"]])),
shiny::hr(style = "border-top: 2px solid gray; height: 10px;")
)
}
)
}
)
})

Expand All @@ -61,7 +61,7 @@ app_ui <- function(id) {
),
shiny::selectInput(ns("selector"), label = NULL, choices = names(data))
)),
shiny::div(
shiny::div(
class = "c-well shiny_filter",
shiny::tags$label("Global Filter", class = "text-primary"),
# shiny::tags$button(
Expand All @@ -73,13 +73,13 @@ app_ui <- function(id) {
# # onclick = sprintf("dv_manager.hide_filters('%s')", ns("global_button"))
# ),
shiny::div(
class = "filter-control filter-filters",
class = "filter-control filter-filters",
dv.filter::data_filter_ui(ns("global_filter"))
)
),
shiny::div(
class = "c-well shiny_filter",
shiny::tags$label("Dataset Filter", class = "text-primary"),
shiny::tags$label("Dataset Filter", class = "text-primary"),
dataset_filters_ui
)
)
Expand Down Expand Up @@ -143,4 +143,4 @@ app_ui <- function(id) {
)),
dataset_name
)
}
}
14 changes: 7 additions & 7 deletions R/pharmaverse_data.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
get_pharmaverse_data <- function(dataset) {
if (!rlang::is_installed("pharmaverseadam")) stop("Please, install.package('pharmaverseadam')")

chr2fct <- function(x){
x[] <- purrr::map(x, ~if(is.character(.x)) factor(.x) else .x)
chr2fct <- function(x) {
x[] <- purrr::map(x, ~ if (is.character(.x)) factor(.x) else .x)
x
}

cd2fct <- function(x){
x[] <- purrr::imap(x, ~if(endsWith(.y, "CD")) factor(.x) else .x)
cd2fct <- function(x) {
x[] <- purrr::imap(x, ~ if (endsWith(.y, "CD")) factor(.x) else .x)
x
}

if (dataset == "adsl") {
res <- pharmaverseadam::adsl |>
res <- pharmaverseadam::adsl |>
chr2fct() |>
cd2fct()
return(res)
}
if (dataset == "adae") {
res <- pharmaverseadam::adae |>
res <- pharmaverseadam::adae |>
chr2fct() |>
cd2fct()
return(res)
}
if (dataset == "adlb") {
res <- pharmaverseadam::adlb |>
res <- pharmaverseadam::adlb |>
chr2fct() |>
cd2fct()
return(res)
Expand Down
6 changes: 3 additions & 3 deletions R/utils_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ get_data_tables_names <- function(data) {
nm <- character(0)
for (idx in seq_along(data)) {
curr_data <- if (is.function(data[[idx]])) data[[idx]]() else data[[idx]]
nm <- union(nm, names(curr_data))
nm <- union(nm, names(curr_data))
}
return(nm)
}

get_dataset_filters_info <- function(data, filter_data) {
dataset_filter_names <- setdiff(get_data_tables_names(data), filter_data)
dataset_filter_names <- setdiff(get_data_tables_names(data), filter_data)
purrr::map(
dataset_filter_names,
function(nm) {
Expand All @@ -76,6 +76,6 @@ get_dataset_filters_info <- function(data, filter_data) {
) |> purrr::set_names(dataset_filter_names)
}

`%||%` <- function(x,y){
`%||%` <- function(x, y) {
if (!is.null(x)) x else y
}
4 changes: 2 additions & 2 deletions tests/testthat/test-shiny_general.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ local({

app$set_inputs("dataset_filter_46ab8635-vars" = "carb")
app$wait_for_idle()
app$set_inputs("dataset_filter_46ab8635-carb" = c(1,1))
app$set_inputs("dataset_filter_46ab8635-carb" = c(1, 1))
app$wait_for_idle()
app$set_inputs("main_tab_panel" = "Filtered Carb")
app$wait_for_idle()
val <- app$wait_for_value(output = "mod5-text", ignore = list("4"), timeout = 10000)
val <- app$wait_for_value(output = "mod5-text", ignore = list("4"), timeout = 10000)
expect_identical(val, "2")
}
)
Expand Down

0 comments on commit 7dced15

Please sign in to comment.