Creates a named list of data_extract_srv
output
data_extract_multiple_srv.Rd
data_extract_multiple_srv
loops over the list of data_extract
given and
runs data_extract_srv
for each one returning a list of reactive objects.
This is suitable as input for data_merge_srv()
.
Usage
data_extract_multiple_srv(data_extract, datasets, ...)
# S3 method for FilteredData
data_extract_multiple_srv(data_extract, datasets, ...)
# S3 method for list
data_extract_multiple_srv(data_extract, datasets, join_keys = NULL, ...)
Arguments
- data_extract
(named
list
ofdata_extract_spec
objects) the listdata_extract_spec
objects. The names of the elements in the list need to correspond to theids
passed todata_extract_ui
. See example for details.- datasets
(
FilteredData
orlist
ofreactive
or non-reactive
data.frame
)
object containing data either in the form of teal.slice::FilteredData or as a list ofdata.frame
. When passing a list of non-reactivedata.frame
objects, they are converted to reactivedata.frame
s internally. When passing a list of reactive or non-reactivedata.frame
objects, the argumentjoin_keys
is required also.- ...
an additional argument
join_keys
is required whendatasets
is a list ofdata.frame
. It shall contain the keys per dataset indatasets
.- join_keys
(
JoinKeys
orNULL
) of join keys per dataset indatasets
.
Value
reactive named list containing outputs from data_extract_srv()
. Output list
names are the same as data_extract
input argument.
Examples
library(shiny)
ADSL <- data.frame(
STUDYID = "A",
USUBJID = LETTERS[1:10],
SEX = rep(c("F", "M"), 5),
AGE = rpois(10, 30),
BMRKR1 = rlnorm(10)
)
datasets <- teal.slice::init_filtered_data(
list(ADSL = list(dataset = ADSL, keys = c("STUDYID", "USUBJID"), parent = character(0))),
join_keys = teal.data::join_keys(
teal.data::join_key("ADSL", "ADSL", c("USUBJID", "STUDYID"))
),
cdisc = TRUE
)
xvar_extract <- data_extract_spec(
dataname = "ADSL",
filter = filter_spec(vars = "SEX", choices = c("F", "M"), selected = "F"),
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "BMRKR1")),
selected = "AGE",
multiple = TRUE,
fixed = FALSE
)
)
yvar_extract <- data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "BMRKR1")),
selected = "BMRKR1",
multiple = TRUE,
fixed = FALSE
)
)
app <- shinyApp(
ui = fluidPage(
teal.widgets::standard_layout(
output = verbatimTextOutput("out1"),
encoding = tagList(
data_extract_ui(id = "xvar", label = "Select x-var", xvar_extract),
data_extract_ui(id = "yvar", label = "Select y-var", yvar_extract),
)
)
),
server = function(input, output, session) {
list_of_reactive_inputs <- data_extract_multiple_srv(
# names of the list corresponding to data_extract_ui ids
list(xvar = xvar_extract, yvar = yvar_extract),
datasets
)
output$out1 <- renderPrint({
lapply(list_of_reactive_inputs(), function(x) x())
})
}
)
if (FALSE) {
runApp(app)
}