Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Keep <- function(f, xs) Filter(Negate(is.null), Map(f, xs))
- # Takes a data frame and filters it by Shiny input values. Each input's name
- # must correspond to a column name in the data frame.
- # Example:
- # output$plot <- renderPlot({
- # mtcars %>%
- # filterer(input$gear, input$carb) %>%
- # ggplot(aes(mpg, disp)) + geom_line()
- # })
- filterer <- function(tbl, ...) {
- quos(...) %>%
- Keep(function(input_name) {
- val <- eval_tidy(input_name)
- if (val != "All") quo(!!call_args(input_name)[[2]] == !!val)
- }, .) %>%
- filter(tbl, !!!.)
- }
Add Comment
Please, Sign In to add comment