Search code examples
rggvis

ggvis filter based on values in multiple columns


I've found ggvis to be fantastic when I need to filter by a column, and this works perfectly (uf refers to the unique factors from that column):

filter(data$Life.stage %in% eval(input_checkboxgroup(uf), selected = uf[[1]])))

However, I've been trying to filter by values in 3 different columns and was wondering if that was possible? If I try to do something like this, then it doesn't work.

filter(data$[,1:3] %in% eval(input_checkboxgroup(c(uf, uf1, uf2), selected = uf[[1]])))

Thanks so much!


Solution

  • I don't know how your data set looks like, and I cannot test the code since you have not provided a reproducible example but if you want to check multiple columns against others you need to use the & operator. So, your filter function should look something like this:

    #this compares first column of data against uf and second column of data
    #against uf1 and so on..
    filter(data[[1]] %in% eval(input_checkboxgroup(uf)  , selected =  uf[[1]]) & 
           data[[2]] %in% eval(input_checkboxgroup(uf1) , selected = uf1[[1]]) &
           data[[3]] %in% eval(input_checkboxgroup(uf2) , selected = uf2[[1]]))