View source: R/data_extract_module.R
data_extract_multiple_srv | R Documentation |
data_extract_srv
outputdata_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.
data_extract_multiple_srv(data_extract, datasets, ...)
## S3 method for class 'reactive'
data_extract_multiple_srv(data_extract, datasets, ...)
## S3 method for class 'FilteredData'
data_extract_multiple_srv(data_extract, datasets, ...)
## S3 method for class 'list'
data_extract_multiple_srv(
data_extract,
datasets,
join_keys = NULL,
select_validation_rule = NULL,
filter_validation_rule = NULL,
dataset_validation_rule = if (is.null(select_validation_rule) &&
is.null(filter_validation_rule)) {
NULL
} else {
shinyvalidate::sv_required("Please select a dataset")
},
...
)
data_extract |
(named See example for details. |
datasets |
( |
... |
An additional argument |
join_keys |
( |
select_validation_rule |
( For more fine-grained control use a list:
If See example for more details. |
filter_validation_rule |
( |
dataset_validation_rule |
( |
reactive named list
containing outputs from data_extract_srv()
.
Output list names are the same as data_extract
input argument.
library(shiny)
library(shinyvalidate)
library(shinyjs)
library(teal.widgets)
iris_select <- data_extract_spec(
dataname = "iris",
select = select_spec(
label = "Select variable:",
choices = variable_choices(iris, colnames(iris)),
selected = "Sepal.Length",
multiple = TRUE,
fixed = FALSE
)
)
iris_filter <- data_extract_spec(
dataname = "iris",
filter = filter_spec(
vars = "Species",
choices = c("setosa", "versicolor", "virginica"),
selected = "setosa",
multiple = TRUE
)
)
data_list <- list(iris = reactive(iris))
ui <- fluidPage(
useShinyjs(),
standard_layout(
output = verbatimTextOutput("out1"),
encoding = tagList(
data_extract_ui(
id = "x_var",
label = "Please select an X column",
data_extract_spec = iris_select
),
data_extract_ui(
id = "species_var",
label = "Please select 2 Species",
data_extract_spec = iris_filter
)
)
)
)
server <- function(input, output, session) {
exactly_2_validation <- function(msg) {
~ if (length(.) != 2) msg
}
selector_list <- data_extract_multiple_srv(
list(x_var = iris_select, species_var = iris_filter),
datasets = data_list,
select_validation_rule = list(
x_var = sv_required("Please select an X column")
),
filter_validation_rule = list(
species_var = compose_rules(
sv_required("Exactly 2 Species must be chosen"),
exactly_2_validation("Exactly 2 Species must be chosen")
)
)
)
iv_r <- reactive({
iv <- InputValidator$new()
compose_and_enable_validators(
iv,
selector_list,
validator_names = NULL
)
})
output$out1 <- renderPrint({
if (iv_r()$is_valid()) {
ans <- lapply(selector_list(), function(x) {
cat(format_data_extract(x()), "\n\n")
})
} else {
"Please fix errors in your selection"
}
})
}
if (interactive()) {
shinyApp(ui, server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.