hkn
hkn

Reputation: 123

Filter function in dplyr throws exception when no filter criteria is chosen

How can I handle that when only one filter criteria or no filter criteria are choosen that no exeption occurs?

temp <-
  df %>%
  filter(
    param1 %in% input$input_1,
    param2 == input$input_2

  )

Upvotes: 0

Views: 68

Answers (1)

pieca
pieca

Reputation: 2573

Apply filtering only when input is not null:

if(is.null(input$input_1)){
  temp <- df # i.e., no filtering
}else{
  temp <- df %>%
    filter(param1 %in% input$input_1)
}

Upvotes: 1

Related Questions