Generate Shiny Query Widget

queryBuilderInput(
  inputId,
  filters,
  rules = list(),
  operators = NULL,
  optgroups,
  default_filter,
  sort_filters = FALSE,
  allow_groups = TRUE,
  allow_rm_groups = TRUE,
  allow_empty = TRUE,
  display_errors = TRUE,
  conditions = c("AND", "OR"),
  default_condition = "AND",
  inputs_separator = " , ",
  display_empty_filter = TRUE,
  select_placeholder = "------",
  lang,
  plugins,
  allow_add_rules = TRUE,
  allow_rm_rules = TRUE,
  .queryBuilderConfig = queryBuilder::queryBuilderConfig
)

updateQueryBuilderInput(
  session,
  inputId,
  rules,
  filters,
  allow_add_rules,
  allow_rm_rules,
  allow_groups,
  allow_rm_groups
)

Arguments

inputId

The input slot that will be used to access the value.

filters

(required) List of available filters in the builder. See queryFilter.

rules

Initial set of rules set with `queryBuilder` package. See queryGroup and queryRule. For `queryRule`, `shinyQueryBuilder` accepts an extra argument `flags`, that consists of four logical elements: `filter_readonly`, `operator_readonly`, `value_readonly` and `no_delete`. These options prevent from changing the rule inputs and removing the rule in the controller. For `queryGroup`, `shinyQueryBuilder` accepts an extra argument `flags`, that consists of four logical elements: `condition_readonly`, `no_add_rule`, `no_add_group` and `no_delete`. These options allow to disable corresponding group management options.

operators

Vector of operator names that should be limited in the input. Leave NULL to allow all of the configured filters.

optgroups

Named list. Configuration of labels for filters and operators. List names should consists of 'optgroup' ids, whereas values, the desired labels to be displayed.

default_filter

Character string. The id of the default filter chosen for any new rule.

sort_filters

Set to `TRUE` to sort filters alphabetically.

allow_groups

Logical or integer. Number of allowed nested groups. TRUE for no limit.

allow_rm_groups

Logical. Should removing groups be enabled.

allow_empty

Logical. No error will be thrown if the builder is entirely empty.

display_errors

Logical (`TRUE`, default). When an error occurs on a rule, display an icon with a tooltip explaining the error.

conditions

Character vector. Array of available group conditions. In order to create custom condition check setQueryConditions.

default_condition

Character string. Default active condition selected for each new group.

inputs_separator

Character string that will be used to separate multiple input controllers for operator values (for operators with `nb_inputs > 1`). Default is ','.

display_empty_filter

Logical. Add an empty option with `select_placeholder` string to the filter dropdowns. If the empty filter is disabled and no default_filter is defined, the first filter will be loaded when adding a rule.

select_placeholder

Character string. An option that can be chosen to select empty filter.

lang

Nested named list providing language translations for selected controller labels. See https://github.com/mistic100/jQuery-QueryBuilder/blob/dev/src/i18n/en.json for the required structure, or load one of the existing files included at https://github.com/mistic100/jQuery-QueryBuilder/blob/dev/src/i18n.

plugins

List of plugins names used for the widget. See https://querybuilder.js.org/plugins.html.

allow_add_rules

Logical. Should adding new rules be enabled.

allow_rm_rules

Logical. Should removing rules be enabled.

.queryBuilderConfig

R6 object of class 'queryBuilderConfig' storing queryOperators. See query-operator.

session

Shiny session object.

Examples


ui <- shiny::fluidPage(
  queryBuilderInput(
    "qb",
    filters = list(
      queryFilter(
        "Species", type = "character", operators = c("in", "equal"),
        values = levels(iris$Species), multiple = TRUE,
        optgroup = "char_fields"
      ),
      queryFilter("Sepal.Length", type = "numeric", values = range(iris$Sepal.Length), optgroup = "num_fields")
    ),
    rules = queryGroup(
      condition = "AND",
      queryRule("Species", "equal", "setosa", flags = list(no_delete = TRUE)),
      queryRule("Sepal.Length", "between", c(5, 7))
    ),
    optgroups = list(num_fields = "Numerical fields", char_fields = "Character fields")
  ),
  shiny::verbatimTextOutput("expr")
)
server <- function(input, output, session) {}

if (interactive()) {
  shiny::runApp(ui, server)
}