`data_extract_filter_srv()` drops `filter$sep` when recomputing choices, so multi-variable `filter_spec` loses its selection
Nessuno ha ancora preso questa issue.
- #298 di @kaipingyang — chiusa senza merge
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 55/100
Direzione di ricerca
Read R/data_extract_filter_module.R, focusing on data_extract_filter_srv() and get_initial_filter_values(), then trace how value_choices() uses filter$sep. Reproduce the reported case with two variables and sep = "~", and check the vals updates after changing columns. Done means recomputed choices preserve the separator and selected values remain valid; add regression coverage for both code paths.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What happens
When a filter_spec() is built on two or more variables with a non-default sep (for example sep = "~"), the filter widget works at first. After the user changes the filter column(s), the observer in data_extract_filter_srv() recomputes the value choices with value_choices() but does not pass filter$sep. The new choices are joined with the default " - ", while filter$selected is still joined with "~". The selected value no longer matches any choice.
Downstream, the extracted filter is split with filter$sep, so the mismatch has two possible outcomes:
- the
valspicker is cleared, the input becomes invalid, and the module never renders, or - a value like
"PRIOR MED - Y"cannot be split on"~", and the resulting filter compares each variable to the whole string, so it matches no rows. The output is empty or all zeros, with no error.
Only filter_specs with two or more vars are affected, because a single-variable filter never joins values.
Reproducible example
library(teal.transform)
library(shiny)
ADSL <- data.frame(
USUBJID = paste0("S", 1:4),
CMCAT = c("PRIOR MED", "PRIOR MED", "CONCOMITANT MED", "CONCOMITANT MED"),
PRIORFL = c("Y", "N", "Y", "N")
)
fs <- filter_spec(
vars = c("CMCAT", "PRIORFL"),
sep = "~",
choices = value_choices(ADSL, c("CMCAT", "PRIORFL"), sep = "~"),
selected = "PRIOR MED~Y",
multiple = FALSE
)
fs$dataname <- "ADSL"
# record every update sent to the `vals` widget
log <- list()
orig <- teal.widgets::updateOptionalSelectInput
utils::assignInNamespace("updateOptionalSelectInput", function(session, inputId, choices = NULL, selected = NULL, ...) {
if (inputId == "vals") log[[length(log) + 1]] <<- list(choices = as.character(choices), selected = selected)
orig(session, inputId, choices = choices, selected = selected, ...)
}, ns = "teal.widgets")
testServer(
teal.transform:::data_extract_filter_srv,
args = list(id = "f", datasets = list(ADSL = reactive(ADSL)), filter = fs),
{
session$setInputs(col = c("CMCAT", "PRIORFL"))
session$setInputs(col = "CMCAT")
session$setInputs(col = c("CMCAT", "PRIORFL"))
}
)
final <- log[[length(log)]]
final$choices
#> [1] "PRIOR MED - Y" "PRIOR MED - N" "CONCOMITANT MED - Y" "CONCOMITANT MED - N"
final$selected
#> [1] "PRIOR MED~Y"
final$selected %in% final$choices
#> [1] FALSE
The first update (from the initial isolate() block) correctly uses filter$choices, which are joined with "~". Every later update from the observeEvent(input$col) handler uses " - ".
Cause
R/data_extract_filter_module.R, inside observeEvent(input$col, ...) (on main as of 2026-11-30):
choices <- value_choices(
datasets[[filter$dataname]](),
input$col,
`if`(isTRUE(input$col == attr(filter$choices, "var_choices")), attr(filter$choices, "var_label"), NULL)
)
sep is not passed, so value_choices() falls back to its default " - ".
get_initial_filter_values() in the same file has the same pattern (value_choices(datasets[[filter$dataname]](), as.character(filter$vars_selected))). It looks like the same bug whenever filter$choices is NULL and more than one variable is selected.
Suggested fix
choices <- value_choices(
datasets[[filter$dataname]](),
input$col,
- `if`(isTRUE(input$col == attr(filter$choices, "var_choices")), attr(filter$choices, "var_label"), NULL)
+ `if`(isTRUE(input$col == attr(filter$choices, "var_choices")), attr(filter$choices, "var_label"), NULL),
+ sep = filter$sep
)
and the same sep = filter$sep in get_initial_filter_values().
The handler also keeps filter$selected even when it is not one of the new choices. The third recorded update above, after switching to a single column, sends selected = "PRIOR MED~Y" together with choices "PRIOR MED" and "CONCOMITANT MED". Keeping only the selected values that are in choices, and otherwise falling back to the existing default, would make this path predictable:
selected <- if (!is.null(filter$selected) && any(filter$selected %in% choices)) {
intersect(filter$selected, choices)
} else if (filter$multiple) {
choices
} else {
choices[1]
}
I'm happy to open a PR with both changes and a test.
Session info
- teal.transform 0.7.2 (CRAN) and
main@1ef30de9 - teal.widgets 0.6.1, shiny 1.15.0, R 4.4.3
- Lingua principale
- R
- Stelle
- 2
- Fork
- 5
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pharmaverse/teal.transform
-
bug core
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
pharmaverse/teal.transform#281 · 1 reazione ·
-
core enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
pharmaverse/teal.transform#280 ·
-
[Bug]: ordering of selected in choices_selected is not respectedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug core
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
pharmaverse/teal.transform#267 · 3 commenti ·
-
bug core
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
pharmaverse/teal.transform#262 ·
-
bug core
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
pharmaverse/teal.transform#258 · 4 commenti · 1 reazione ·
Tutte le issue di pharmaverse/teal.transform
Issue simili
-
num_ode_rk4_adaptive rejects atol = 0 while accepting rtol = 0 and while num_ode_dopri5 accepts bothApertaarea/ode-pde good first issue help wanted kind/contract severity/4-minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Apich-Organization/rssn#383 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
PRL-PRG/r-compile-server#70 · 1 commento ·
-
dependencies docker enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
posit-dev/images-workbench#257 ·
I maintainer di solito rispondono entro 1 giorno
-
dependencies docker enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
posit-dev/images-package-manager#188 ·
I maintainer di solito rispondono entro 1 giorno
-
dependencies docker enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
posit-dev/images-connect#222 ·
I maintainer di solito rispondono entro 1 giorno