with_args() sets arguments for the inputs filterInput() creates for one
or more columns of a configuration made by shinyfilters(), such as a
slider's value, step, or width. Each column keeps its input.
Arguments
- .filters
A configuration created by
shinyfilters().- ...
Any number of formulas.
cols ~ list(arg = value, ...): the columns on the left, their arguments on the right.
Arguments replace the ones shinyfilters passes for the column, such as
label,choices,min,max, andvalue.inputIdcan't be set: an input's id is always its column's name..update_fn = fnnames the function that updates the input instead, as described inwith_filters().A value can use
.x, the column the input is created for. It is evaluated when the input is created, and a call in it that takesna.rm, such asrange(.x), getsna.rm = TRUEunless it setsna.rmitself. Other values are evaluated right away, and can use the columns too, as they are at that point.
Details
Arguments stay with their column. Setting one again replaces it, and an
input chosen later with with_filters() keeps the ones it has an argument
for.
See also
with_filters() to choose inputs, with_defaults() to set
arguments for every column.
Examples
filters <- shinyfilters(nyc_flights)
# A range slider: `.x` is the column the input is created for
filters <- with_args(filters, dep_delay ~ list(value = range(.x)))
filters$dep_delay
#> <div class="form-group shiny-input-container">
#> <label class="control-label" id="dep_delay-label" for="dep_delay">dep_delay</label>
#> <input class="js-range-slider" id="dep_delay" data-skin="shiny" data-type="double" data-min="-12" data-max="397" data-from="-12" data-to="397" data-step="1" data-grid="true" data-grid-num="9.97560975609756" data-grid-snap="false" data-prettify-separator="," data-prettify-enabled="true" data-keyboard="true" data-drag-interval="true" data-data-type="number"/>
#> </div>
# Several arguments
with_args(filters, dep_delay ~ list(value = range(.x), step = 5))
#> <shinyfilters> • 7 filters
#>
#> Filters
#> date <date> dateRangeInput
#> carrier <chr> selectizeInput
#> origin <fct> selectizeInput
#> dest <chr> selectizeInput
#> dep_delay <dbl> sliderInput
#> value = range(.x, na.rm = TRUE)
#> step = 5
#> distance <dbl> sliderInput
#> delayed <lgl> selectizeInput
# The same arguments for several columns
with_args(filters, c(dep_delay, distance) ~ list(value = range(.x)))
#> <shinyfilters> • 7 filters
#>
#> Filters
#> date <date> dateRangeInput
#> carrier <chr> selectizeInput
#> origin <fct> selectizeInput
#> dest <chr> selectizeInput
#> dep_delay <dbl> sliderInput
#> value = range(.x, na.rm = TRUE)
#> distance <dbl> sliderInput
#> value = range(.x, na.rm = TRUE)
#> delayed <lgl> selectizeInput
# Different arguments for different columns
with_args(
filters,
dep_delay ~ list(step = 5),
origin ~ list(label = "Airport")
)
#> <shinyfilters> • 7 filters
#>
#> Filters
#> date <date> dateRangeInput
#> carrier <chr> selectizeInput
#> origin <fct> selectizeInput
#> label = "Airport"
#> dest <chr> selectizeInput
#> dep_delay <dbl> sliderInput
#> value = range(.x, na.rm = TRUE)
#> step = 5
#> distance <dbl> sliderInput
#> delayed <lgl> selectizeInput