Guest User

Untitled

a guest
May 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. Keep <- function(f, xs) Filter(Negate(is.null), Map(f, xs))
  2.  
  3. # Takes a data frame and filters it by Shiny input values. Each input's name
  4. # must correspond to a column name in the data frame.
  5. # Example:
  6. # output$plot <- renderPlot({
  7. # mtcars %>%
  8. # filterer(input$gear, input$carb) %>%
  9. # ggplot(aes(mpg, disp)) + geom_line()
  10. # })
  11. filterer <- function(tbl, ...) {
  12. quos(...) %>%
  13. Keep(function(input_name) {
  14. val <- eval_tidy(input_name)
  15. if (val != "All") quo(!!call_args(input_name)[[2]] == !!val)
  16. }, .) %>%
  17. filter(tbl, !!!.)
  18. }
Add Comment
Please, Sign In to add comment