-
-
Notifications
You must be signed in to change notification settings - Fork 5
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 available slices #377
Changes from 5 commits
01b620e
6166519
4e706c3
6c90306
9fb0e5d
9fa2126
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -482,7 +482,7 @@ FilteredData <- R6::R6Class( # nolint | |||||||||
private$module_add <- module_add | ||||||||||
} | ||||||||||
|
||||||||||
lapply(datanames, function(dataname) { | ||||||||||
lapply(self$datanames(), function(dataname) { | ||||||||||
states <- Filter(function(x) identical(x$dataname, dataname), state) | ||||||||||
private$get_filtered_dataset(dataname)$set_filter_state(states) | ||||||||||
}) | ||||||||||
|
@@ -591,7 +591,10 @@ FilteredData <- R6::R6Class( # nolint | |||||||||
#' @return invisible `NULL` | ||||||||||
set_available_teal_slices = function(x) { | ||||||||||
checkmate::assert_class(x, "reactive") | ||||||||||
private$available_teal_slices <- x | ||||||||||
private$available_teal_slices <- reactive({ | ||||||||||
# we want to limit the available filters to the ones that are relevant for this FilteredData | ||||||||||
Filter(function(x) x$dataname %in% self$datanames(), x()) | ||||||||||
}) | ||||||||||
invisible(NULL) | ||||||||||
}, | ||||||||||
|
||||||||||
|
@@ -1073,7 +1076,6 @@ FilteredData <- R6::R6Class( # nolint | |||||||||
# appropriate filter (identified by it's id) | ||||||||||
srv_available_filters = function(id) { | ||||||||||
moduleServer(id, function(input, output, session) { | ||||||||||
slices <- reactive(Filter(function(slice) !isTRUE(slice$locked), private$available_teal_slices())) | ||||||||||
slices_interactive <- reactive( | ||||||||||
Filter( | ||||||||||
function(slice) !isTRUE(slice$fixed) && !inherits(slice, "teal_slice_expr"), | ||||||||||
|
@@ -1086,8 +1088,16 @@ FilteredData <- R6::R6Class( # nolint | |||||||||
private$available_teal_slices() | ||||||||||
) | ||||||||||
) | ||||||||||
available_slices_id <- reactive(vapply(slices(), `[[`, character(1), "id")) | ||||||||||
available_slices_id <- reactive(vapply(private$available_teal_slices(), `[[`, character(1), "id")) | ||||||||||
active_slices_id <- reactive(vapply(self$get_filter_state(), `[[`, character(1), "id")) | ||||||||||
duplicated_slice_references <- reactive({ | ||||||||||
# slice refers to a particular column | ||||||||||
slice_reference <- vapply(private$available_teal_slices(), get_default_slice_id, character(1)) | ||||||||||
is_duplicated_reference <- duplicated(slice_reference) | duplicated(slice_reference, fromLast = TRUE) | ||||||||||
is_active <- available_slices_id() %in% active_slices_id() | ||||||||||
is_not_expr <- vapply(private$available_teal_slices(), inherits, logical(1), "teal_slice_expr") | ||||||||||
slice_reference[is_duplicated_reference & is_active & !is_not_expr] | ||||||||||
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.
Suggested change
|
||||||||||
}) | ||||||||||
|
||||||||||
checkbox_group_element <- function(name, value, label, checked, disabled = FALSE) { | ||||||||||
tags$div( | ||||||||||
|
@@ -1113,45 +1123,53 @@ FilteredData <- R6::R6Class( # nolint | |||||||||
selected = NULL | ||||||||||
) | ||||||||||
active_slices_ids <- active_slices_id() | ||||||||||
|
||||||||||
shiny::isolate({ | ||||||||||
interactive_choice_mock <- lapply( | ||||||||||
slices_interactive(), | ||||||||||
function(slice) { | ||||||||||
duplicated_slice_refs <- duplicated_slice_references() | ||||||||||
interactive_choice_mock <- lapply( | ||||||||||
slices_interactive(), | ||||||||||
function(slice) { | ||||||||||
# we need to isolate changes in the fields of the slice (teal_slice) | ||||||||||
shiny::isolate({ | ||||||||||
checkbox_group_element( | ||||||||||
name = session$ns("available_slices_id"), | ||||||||||
value = slice$id, | ||||||||||
label = slice$id, | ||||||||||
checked = if (slice$id %in% active_slices_ids) "checked", | ||||||||||
disabled = slice$locked | ||||||||||
disabled = slice$locked || | ||||||||||
get_default_slice_id(slice) %in% duplicated_slice_refs && | ||||||||||
!slice$id %in% active_slices_ids | ||||||||||
) | ||||||||||
} | ||||||||||
) | ||||||||||
}) | ||||||||||
} | ||||||||||
) | ||||||||||
|
||||||||||
non_interactive_choice_mock <- lapply( | ||||||||||
slices_fixed(), | ||||||||||
function(slice) { | ||||||||||
non_interactive_choice_mock <- lapply( | ||||||||||
slices_fixed(), | ||||||||||
function(slice) { | ||||||||||
# we need to isolate changes in the fields of the slice (teal_slice) | ||||||||||
isolate( | ||||||||||
checkbox_group_element( | ||||||||||
name = session$ns("available_slices_id"), | ||||||||||
value = slice$id, | ||||||||||
label = slice$id, | ||||||||||
checked = if (slice$id %in% active_slices_ids) "checked", | ||||||||||
disabled = slice$locked | ||||||||||
disabled = slice$locked || | ||||||||||
get_default_slice_id(slice) %in% duplicated_slice_refs && | ||||||||||
!slice$id %in% active_slices_ids | ||||||||||
) | ||||||||||
} | ||||||||||
) | ||||||||||
) | ||||||||||
} | ||||||||||
) | ||||||||||
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. Perhaps assign the |
||||||||||
|
||||||||||
htmltools::tagInsertChildren( | ||||||||||
checkbox, | ||||||||||
br(), | ||||||||||
tags$strong("Fixed filters"), | ||||||||||
non_interactive_choice_mock, | ||||||||||
tags$strong("Iteractive filters"), | ||||||||||
interactive_choice_mock, | ||||||||||
.cssSelector = "div.shiny-options-group", | ||||||||||
after = 0 | ||||||||||
) | ||||||||||
}) | ||||||||||
htmltools::tagInsertChildren( | ||||||||||
checkbox, | ||||||||||
br(), | ||||||||||
tags$strong("Fixed filters"), | ||||||||||
non_interactive_choice_mock, | ||||||||||
tags$strong("Iteractive filters"), | ||||||||||
interactive_choice_mock, | ||||||||||
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. |
||||||||||
.cssSelector = "div.shiny-options-group", | ||||||||||
after = 0 | ||||||||||
) | ||||||||||
}) | ||||||||||
|
||||||||||
observeEvent(input$available_slices_id, ignoreNULL = FALSE, ignoreInit = TRUE, { | ||||||||||
|
@@ -1160,22 +1178,22 @@ FilteredData <- R6::R6Class( # nolint | |||||||||
if (length(new_slices_id)) { | ||||||||||
new_teal_slices <- Filter( | ||||||||||
function(slice) slice$id %in% new_slices_id, | ||||||||||
slices() | ||||||||||
private$available_teal_slices() | ||||||||||
) | ||||||||||
self$set_filter_state(new_teal_slices) | ||||||||||
} | ||||||||||
|
||||||||||
if (length(removed_slices_id)) { | ||||||||||
removed_teal_slices <- Filter( | ||||||||||
function(slice) slice$id %in% removed_slices_id, | ||||||||||
slices() | ||||||||||
self$get_filter_state() | ||||||||||
) | ||||||||||
self$remove_filter_state(removed_teal_slices) | ||||||||||
} | ||||||||||
}) | ||||||||||
|
||||||||||
observeEvent(slices(), ignoreNULL = FALSE, { | ||||||||||
if (length(slices())) { | ||||||||||
observeEvent(private$available_teal_slices(), ignoreNULL = FALSE, { | ||||||||||
if (length(private$available_teal_slices())) { | ||||||||||
shinyjs::show("available_menu") | ||||||||||
} else { | ||||||||||
shinyjs::hide("available_menu") | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -183,15 +183,11 @@ DefaultFilteredDataset <- R6::R6Class( # nolint | |||||||||||||||||
set_filter_state = function(state) { | ||||||||||||||||||
shiny::isolate({ | ||||||||||||||||||
logger::log_trace("{ class(self)[1] }$set_filter_state initializing, dataname: { private$dataname }") | ||||||||||||||||||
checkmate::assert_class(state, "teal_slices") | ||||||||||||||||||
lapply(state, function(x) { | ||||||||||||||||||
checkmate::assert_true( | ||||||||||||||||||
shiny::isolate(x$dataname) == private$dataname, | ||||||||||||||||||
.var.name = "dataname matches private$dataname" | ||||||||||||||||||
) | ||||||||||||||||||
private$get_filter_states()[[1L]]$set_filter_state(state = state) | ||||||||||||||||||
logger::log_trace("{ class(self)[1] }$set_filter_state initialized, dataname: { private$dataname }") | ||||||||||||||||||
lapply(state, function(slice) { | ||||||||||||||||||
checkmate::assert_true(slice$dataname == private$dataname) | ||||||||||||||||||
}) | ||||||||||||||||||
checkmate::assert_class(state, "teal_slices") | ||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||
private$get_filter_states()[[1L]]$set_filter_state(state = state) | ||||||||||||||||||
invisible(NULL) | ||||||||||||||||||
}) | ||||||||||||||||||
}, | ||||||||||||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 guess these lines above can be removed now: