0

I have a Shiny app that takes input from radio button and then use that to perform filter to the data frame using dplyr in the server side. It works, but now I want to expand it to take multiple inputs to filter, and I have no idea how to do it.

To illustrate, it's something like this in ui.R

radioButtons(
  inputId = "selectPrincipal",
  choices = c("a", "b", "c")
)

And selection in server.R like this

output$PrincipalValue <- renderText({
  x <- df %>%
    filter(Principal==input$selectPrincipal) %>%
    summarize(total=sum(Value))
  prettyNum(x$total, big.mark=",")
})

df would contain something like this

> df
Source: local data frame [10 x 2]

   Principal Value
1          a     4
2          a     1
3          a     1
4          a     3
5          b     4
6          b     2
7          b     2
8          b     3
9          c     2
10         c     1

The above set up works. Now say I want to introduce a new radio button selection called "All". What value should I pass to filter(Principal== in server.R above? Is there a wild card in dplyr to filter keeping all? Or is there another approach equivalent to concatenating all the values (I can't figure out the syntax though)?

In a way I guess this question is asking the same as this one on RODBC multiple inputs from shiny, but am wondering if there is a different approach for dplyr.

Community
  • 1
  • 1
Ricky
  • 4,616
  • 6
  • 42
  • 72

1 Answers1

1
Principal == input$selectPrincipal | input$selectPrincipal == "All"
Nick Kennedy
  • 12,510
  • 2
  • 30
  • 52