Title: | 'jQuery QueryBuilder' Input for 'Shiny' |
Version: | 1.0.3 |
Description: | A highly configurable 'jQuery' plugin offering a simple interface to create complex queries/filters in 'Shiny'. The outputted rules can easily be parsed into a set of 'R' and/or 'SQL' queries and used to filter data. Custom parsing of the rules is also supported. For more information about 'jQuery QueryBuilder' see https://querybuilder.js.org/. |
License: | MIT + file LICENSE |
URL: | https://github.com/hfshr/jqbr, https://hfshr.github.io/jqbr/ |
BugReports: | https://github.com/hfshr/jqbr/issues |
Imports: | htmltools, jsonlite, shiny |
Suggests: | bslib, packer, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2023-08-12 10:00:39 UTC; harry |
Author: | Harry Fisher [aut, cre] |
Maintainer: | Harry Fisher <harryfisher21@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-08-15 06:50:02 UTC |
Apply query to a dataframe
Description
Filter a dataframe using the output of a queryBuilder. The return_value
Should be set to r_rules
, and the list of filters should contain column names
that are present in the data as their id value.
Usage
filter_table(data = NULL, filters = NULL)
Arguments
data |
|
filters |
output from queryBuilder when |
Value
A filtered version of the input data.frame
Examples
library(shiny)
library(jqbr)
filters <- list(
list(
id = "cyl",
type = "integer",
input = "radio",
values = list(
4,
6,
8
)
)
)
ui <- fluidPage(
queryBuilderInput(
inputId = "r_filter",
filters = filters,
return_value = "r_rules"
),
tableOutput("cars")
)
server <- function(input, output) {
output$cars <- renderTable({
filter_table(mtcars, input$r_filter)
})
}
if (interactive()) {
shinyApp(ui, server)
}
queryBuilderInput
Description
Shiny input bindings for queryBuilder.
Usage
queryBuilderInput(
inputId,
width = "100%",
filters,
plugins = NULL,
rules = NULL,
optgroups = NULL,
default_filter = NULL,
sort_filters = FALSE,
allow_groups = TRUE,
allow_empty = FALSE,
display_errors = FALSE,
conditions = c("AND", "OR"),
default_condition = "AND",
inputs_separator = ",",
display_empty_filter = TRUE,
select_placeholder = "------",
operators = NULL,
add_na_filter = FALSE,
return_value = c("r_rules", "rules", "sql", "all")
)
Arguments
inputId |
string. Input id for the builder. |
width |
Width of the builder. Default if "100%". |
filters |
list of list specifying the available filters in the builder. See example for a See https://querybuilder.js.org/#filters for details on the possible options |
plugins |
list of optional plugins. |
rules |
Initial set of rules. By default the builder will contain one empty rule |
optgroups |
List of groups in the filters and operators dropdowns. |
default_filter |
string. The |
sort_filters |
boolean \| string. Sort filters alphabetically, or with a custom JS function. |
allow_groups |
boolean \| integer. Number of allowed nested groups.
|
allow_empty |
boolean. If |
display_errors |
boolean. If |
conditions |
string. Array of available group conditions. Use the
|
default_condition |
Default active condition. Default 'AND'. |
inputs_separator |
string used to separate multiple inputs (for between operator). default is ",". |
display_empty_filter |
boolean. Default |
select_placeholder |
string. Label of the "no filter" option. |
operators |
NULL or list. If a list, format should follow that described here: https://querybuilder.js.org/#operators |
add_na_filter |
bool. Default is FALSE .If |
return_value |
string. On of |
Value
A htmltools::tagList()
containing the queryBuilder
dependencies and configuration that can be added to a shiny UI definition.
Examples
library(shiny)
library(jqbr)
ui <- fluidPage(
useQueryBuilder(),
queryBuilderInput(
inputId = "qb",
filters = list(
list(
id = "name",
type = "string"
)
)
)
)
server <- function(input, output) {
observeEvent(input$qb, {
print(input$qb)
})
}
# Add is_na filter
ui <- fluidPage(
useQueryBuilder(),
queryBuilderInput(
inputId = "qb",
add_na_filter = TRUE,
return_value = "r_rules",
filters = list(
list(
id = "name",
type = "string"
)
)
)
)
server <- function(input, output) {
observeEvent(input$qb, {
print(input$qb)
})
}
if (interactive()) {
shinyApp(ui, server)
}
run_jqbr_demo
Description
Run the jqbr demo app
Usage
run_jqbr_demo()
Value
A Shiny app
Examples
if (interactive()) {
run_jqbr_demo()
}
updateQueryBuilder
Description
Update a queryBuilder with available methods.
Usage
updateQueryBuilder(
inputId,
setFilters = NULL,
addFilter = NULL,
setRules = NULL,
destroy = FALSE,
reset = FALSE,
session = shiny::getDefaultReactiveDomain()
)
Arguments
inputId |
inputId of builder to update. |
setFilters |
list of lists container new filters. |
addFilter |
Named list containing |
setRules |
List of rules apply to the builder. |
destroy |
bool. |
reset |
bool. |
session |
The session object passed to function given to shinyServer. Default is getDefaultReactiveDomain(). |
Value
An updated queryBuilderInput()
Examples
library(shiny)
library(jqbr)
# Button to reset the build an remove all rules
ui <- fluidPage(
useQueryBuilder(),
queryBuilderInput(
inputId = "qb",
filters = list(
list(
id = "name",
type = "string"
)
)
),
actionButton("reset", "Reset")
)
server <- function(input, output) {
observeEvent(input$reset, {
updateQueryBuilder(
inputId = "qb",
reset = TRUE
)
})
}
if (interactive()) {
shinyApp(ui, server)
}
useQueryBuilder
Description
Make a call to useQueryBuilder
in your ui code to load the
required dependencies for the queryBuilder and optionally specify the
bootstrap version to use.
Usage
useQueryBuilder(bs_version = c("3", "4", "5"))
Arguments
bs_version |
The version of bootstrap to use with the builder. Possible values are "3", "4" or "5" |
Value
list. html dependency for queryBuilderBinding.
See htmltools::htmlDependency()
for further information.