Column selection input specification
select_spec.Rd
select_spec
is used inside teal to create a selectInput
that will select columns from a dataset.
Usage
select_spec(
choices,
selected = if (inherits(choices, "delayed_data")) NULL else choices[1],
multiple = length(selected) > 1 || inherits(selected, "all_choices"),
fixed = FALSE,
always_selected = NULL,
ordered = FALSE,
label = "Select"
)
select_spec.delayed_data(
choices,
selected = NULL,
multiple = length(selected) > 1,
fixed = FALSE,
always_selected = NULL,
ordered = FALSE,
label = NULL
)
select_spec.default(
choices,
selected = choices[1],
multiple = length(selected) > 1,
fixed = FALSE,
always_selected = NULL,
ordered = FALSE,
label = NULL
)
Arguments
- choices
(
character
) or (delayed_data
) object. Named character vector to define the choices of a shinyselectInput
. These have to be columns in the dataset defined in thedata_extract_spec
where this is called.delayed_data
objects can be created viavariable_choices
orvalue_choices
.- selected
optional (
character
orNULL
orall_choices
ordelayed_data
object). Named character vector to define the selected values of a shinyselectInput
. Passing anall_choices()
object indicates selecting all possible choices. Defaults to the first value ofchoices
orNULL
for delayed data loading.- multiple
(
logical
) Whether multiple values shall be allowed in the shinyselectInput
.- fixed
optional (
logical
).data_extract_spec
specific feature to hide the choices selected in case they are not needed. Setting fixed toTRUE
will not allow the user to select columns. It will then lead to a selection of columns in the dataset that is defined by the developer of the app.- always_selected
(
character
) Additional column names from the data set that should always be selected- ordered
(
logical(1)
) Flags whether selection order should be tracked.- label
optional (
character
). Define a label on top of this specific shinyselectInput
. The default value is"Select"
.
Value
A select_spec
-S3 class object or delayed_select_spec
-S3-class object.
It contains all input values.
If select_spec
, then the function double checks the choices
and selected
inputs.
Details
To give you some more insights into this function there are several examples. These all
start by a data set containing the columns "AGE"
, "AVAL"
and "BMRKR1"
.
-
Selection with just one column allowed
select = select_spec( choices = c("AVAL", "BMRKR1", "AGE"), selected = c("AVAL"), multiple = FALSE, fixed = FALSE, label = "Column" )
-
Selection with just multiple columns allowed
select = select_spec( choices = c("AVAL", "BMRKR1", "AGE"), selected = c("AVAL", "BMRKR1"), multiple = TRUE, fixed = FALSE, label = "Columns" )
-
Selection without user access
select = select_spec( choices = c("AVAL", "BMRKR1"), selected = c("AVAL", "BMRKR1"), multiple = TRUE, fixed = TRUE, label = "Columns" )
-
Delayed version
adsl_select <- select_spec( label = "Select variable:", choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE )
-
all_choices passed to selected
adsl_select <- select_spec( label = "Select variable:", choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), selected = all_choices() )
Examples
# functional form (subsetting for factor variables only) of select_spec with delayed data loading
select_spec(
choices = variable_choices("ADSL", subset = function(data) {
idx <- vapply(data, is.factor, logical(1))
return(names(data)[idx])
}),
# setting first factor variable as default
selected = variable_choices("ADSL", subset = function(data) {
idx <- vapply(data, is.factor, logical(1))
return(names(data)[idx][1])
}),
multiple = TRUE
)
#> select_spec with delayed data: ADSL
#> $ choices
#> variable_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ subset
#> function(data) {
#> idx <- vapply(data, is.factor, logical(1))
#> return(names(data)[idx])
#> }
#> <environment: 0x55f66416ac30>
#> $ key
#> NULL
#> $ selected
#> variable_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ subset
#> function(data) {
#> idx <- vapply(data, is.factor, logical(1))
#> return(names(data)[idx][1])
#> }
#> <environment: 0x55f66416ac30>
#> $ key
#> NULL
#> $ multiple
#> [1] TRUE
#> $ fixed
#> [1] FALSE
#> $ always_selected
#> NULL
#> $ ordered
#> [1] FALSE
#> $ label
#> [1] "Select"
# Both below objects are semantically the same
select_spec(choices = variable_choices("ADSL"), selected = variable_choices("ADSL"))
#> select_spec with delayed data: ADSL
#> $ choices
#> variable_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ subset
#> NULL
#> $ key
#> NULL
#> $ selected
#> variable_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ subset
#> NULL
#> $ key
#> NULL
#> $ multiple
#> [1] TRUE
#> $ fixed
#> [1] FALSE
#> $ always_selected
#> NULL
#> $ ordered
#> [1] FALSE
#> $ label
#> [1] "Select"
select_spec(choices = variable_choices("ADSL"), selected = all_choices())
#> select_spec with delayed data: ADSL
#> $ choices
#> variable_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ subset
#> NULL
#> $ key
#> NULL
#> $ selected
#> variable_choices with delayed data: ADSL
#> $ data
#> [1] "ADSL"
#> $ subset
#> NULL
#> $ key
#> NULL
#> $ multiple
#> [1] TRUE
#> $ fixed
#> [1] FALSE
#> $ always_selected
#> NULL
#> $ ordered
#> [1] FALSE
#> $ label
#> [1] "Select"