Create sets of data filters in Shiny applications with ease, with lots of customization options.
Features
To define a filter set, we use data_filter
and shinyfilterset
:
my_filters <- shinyfilterset(data = mtcars,
data_filter("drat", "picker", "Rear Axle Ratio"),
data_filter("cyl", "slider", "Number of cylinder"),
data_filter("gear", "checkboxes", "gears")
)
Here the first argument to data_filter
is the column name of the dataset you wish to filter, then a UI for the filter (which can be customized), and then a label to apply to the filter.
Then, in the UI of a shiny app, all you have to do to generate the HTML of the filter set:
my_filters$ui()
In the server section, we provide a filtered dataset by using the apply
method:
observe({
rv$mtcars_filtered <- my_filters$apply(mtcars)
})
where rv
is a reactiveValues
(but you can do whatever you want). The apply
method is reactive itself, so the filters will be applied whenever the user changes any settings.
To reset the filters to the original state (and thus resetting the filtered data), we just have to tie the reset_all
method to say, a button:
observeEvent(input$btn_reset, {
my_filters$reset_all()
})
remotes::install_bitbucket("shintolabs/shinyfilterset", auth_user = "YOU", password = "PASS")
Wesley Brants
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.