mercredi 7 novembre 2018

Filter multiple columns by value using Checkbox group

How can I use a checkbox group to filter several columns by value? See example below: I want to return only the rows for which the columns indicated by the checkbox group have the value "yes".

---
title: "test"
runtime: shiny
output: 
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
```

```{r}
checkboxGroupInput("checkGroup", label = h3("Checkbox group"), 
choices = list("col1", "col2"))
```

```{r}
df <- data.frame(c(1,2,3),c("no","yes","yes"),c("no","no","yes"))
colnames(df)<-c("id","col1","col2")
```
```{r}
renderDataTable({
    df        
})
```

ie when selecting "col1', the output should contain only row row#2 and 3, when selecting "col2', the output should be: row#3, when selecting both "col1" and "col2", the output should be: row#2 and 3.

I could write an if statement for each variable but I'd rather not (I have 10 or so). Surely there must be a better way?




Aucun commentaire:

Enregistrer un commentaire