Data extract filter specification
filter_spec.Rd
Arguments
- vars
(
character
) or (delayed_data
) object. Character vector giving the columns to be filtered. These should be key variables of the data set to be filtered.delayed_data
objects can be created viavariable_choices()
,value_choices()
, orchoices_selected
.- choices
-
(
character
ornumeric
orlogical
or (delayed_data
) object. Named character vector to define the choices of a shinyselectInput
. These choices will be used to filter the dataset.These shall be filter values of the
vars
input separated by the separator(sep
). Please watch out that the filter values have to follow the order of thevars
input. In the following example we will show how to filter two columns:vars = c("PARAMCD","AVISIT")
andchoices = c("CRP - BASELINE", "ALT - BASELINE")
will lead to a filtering of(PARAMCD == "CRP" & AVISIT == "BASELINE") | (PARAMCD == "ALT" & AVISIT == "BASELINE")
.The
sep
input has to be" - "
in this case.delayed_data
objects can be created viavariable_choices
orvalue_choices
. - selected
(
character
ornumeric
orlogical
or (delayed_data
or (all_choices
)) object. Named character vector to define the selected values of a shinyselectInput
(default values). This value will be displayed inside the shiny app upon start. Theall_choices
object indicates selecting all possible choices.- multiple
(
logical
) Whether multiple values shall be allowed in the shinyselectInput
.- label
optional (
character
). Define a label on top of this specific shinyselectInput
. The default value is"Filter by"
.- sep
(
character
) A separator string to split thechoices
orselected
inputs into the values of the different columns- drop_keys
optional, (
logical
) whether to drop filter column from the dataset keys,TRUE
on default.
Details
The filter_spec
is used inside teal
apps to allow filtering datasets
for their key variables. Imagine having an adverse events table. It has
the columns PARAMCD
and CNSR
. PARAMCD
contains the levels
"OS"
, "PFS"
, "EFS"
. CNSR
contains the levels "0"
and "1"
.
The following examples should show how a filter_spec
setup will influence
the drop-down menu the app user will see:
-
Filtering two variables
filter_spec( vars = c("PARAMCD", "CNSR"), sep = "-", choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), selected = "OS-1", multiple = FALSE, label = "Choose endpoint and Censor" )
-
Filtering a single variable
filter_spec( vars = c("PARAMCD"), sep = "-", choices = c("OS", "PFS", "EFS"), selected = "OS", multiple = FALSE, label = "Choose endpoint" )
-
Filtering a single variable by multiple levels of the variable
filter_spec( vars = c("PARAMCD"), sep = "-", choices = c("OS", "PFS", "EFS"), selected = c("OS", "PFS"), multiple = TRUE, label = "Choose endpoint" )
-
Delayed version
adsl_filter <- filter_spec( vars = variable_choices("ADSL", "SEX"), sep = "-", choices = value_choices("ADSL", "SEX", "SEX"), selected = "F", multiple = FALSE, label = "Choose endpoint and Censor" )
-
Using
choices_selected
adsl_filter <- filter_spec( vars = choices_selected(variable_choices("ADSL", subset = c("SEX", "AGE")), "SEX", fixed = FALSE), multiple = TRUE ) adsl_filter2 <- filter_spec( vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = TRUE), multiple = TRUE )
-
Choose all choices
adsl_filter <- filter_spec( vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = FALSE), choices = value_choices("ADSL", "SEX"), selected = all_choices() )
Examples
filter_spec(
vars = c("PARAMCD", "AVISIT"),
sep = " - ",
choices = c("CRP - BASELINE", "CRP - SCREENING", "ALT - BASELINE"),
selected = c("CRP - BASELINE"),
multiple = TRUE
)
#> filter_spec with delayed data:
#> $ vars_choices
#> [1] "PARAMCD" "AVISIT"
#> $ vars_selected
#> [1] "PARAMCD" "AVISIT"
#> $ vars_label
#> NULL
#> $ vars_fixed
#> [1] TRUE
#> $ vars_multiple
#> [1] TRUE
#> $ choices
#> [1] "CRP - BASELINE" "CRP - SCREENING" "ALT - BASELINE"
#> $ selected
#> [1] "CRP - BASELINE"
#> $ label
#> [1] "Filter by"
#> $ multiple
#> [1] TRUE
#> $ fixed
#> [1] FALSE
#> $ sep
#> [1] " - "
#> $ drop_keys
#> [1] FALSE
#> $ dataname
#> NULL
#> $ initialized
#> [1] FALSE
filter_spec(
vars = c("PARAMCD"),
sep = " - ",
choices = c("CRP", "ALT"),
selected = c("CRP"),
multiple = TRUE
)
#> filter_spec with delayed data:
#> $ vars_choices
#> [1] "PARAMCD"
#> $ vars_selected
#> [1] "PARAMCD"
#> $ vars_label
#> NULL
#> $ vars_fixed
#> [1] TRUE
#> $ vars_multiple
#> [1] TRUE
#> $ choices
#> [1] "CRP" "ALT"
#> $ selected
#> [1] "CRP"
#> $ label
#> [1] "Filter by"
#> $ multiple
#> [1] TRUE
#> $ fixed
#> [1] FALSE
#> $ sep
#> [1] " - "
#> $ drop_keys
#> [1] FALSE
#> $ dataname
#> NULL
#> $ initialized
#> [1] FALSE
filter_spec(
vars = variable_choices("ADSL", "ARMCD"),
choices = value_choices("ADSL",
var_choices = "ARMCD", var_label = "ARM",
subset = function(data) {
levels(data$ARMCD)[1:2]
}
),
selected = value_choices("ADSL",
var_choices = "ARMCD", var_label = "ARM",
subset = function(data) {
levels(data$ARMCD)[1]
}
)
)
#> filter_spec with delayed data:
#> $ vars_choices
#> variable_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ subset
#> [1] "ARMCD"
#> $ key
#> NULL
#> $ vars_selected
#> variable_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ subset
#> [1] "ARMCD"
#> $ key
#> NULL
#> $ vars_label
#> NULL
#> $ vars_fixed
#> [1] TRUE
#> $ vars_multiple
#> [1] TRUE
#> $ choices
#> value_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ var_choices
#> [1] "ARMCD"
#> $ var_label
#> [1] "ARM"
#> $ subset
#> function(data) {
#> levels(data$ARMCD)[1:2]
#> }
#> <environment: 0x55f668f27d48>
#> $ sep
#> [1] " - "
#> $ selected
#> value_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ var_choices
#> [1] "ARMCD"
#> $ var_label
#> [1] "ARM"
#> $ subset
#> function(data) {
#> levels(data$ARMCD)[1]
#> }
#> <environment: 0x55f668f27d48>
#> $ sep
#> [1] " - "
#> $ label
#> [1] "Filter by"
#> $ multiple
#> [1] TRUE
#> $ fixed
#> [1] FALSE
#> $ sep
#> [1] " - "
#> $ drop_keys
#> [1] FALSE
#> $ dataname
#> NULL
#> $ initialized
#> [1] FALSE