dplyr来自Shiny的多个输入

时间:2015-06-23 03:58:41

标签: r shiny dplyr

我有一个Shiny app,它从单选按钮获取输入,然后使用它来使用服务器端的dplyr对数据帧进行过滤。它有效,但现在我想扩展它以采取多个输入来过滤,我不知道该怎么做。

为了说明,ui.R

中有类似的内容
radioButtons(
  inputId = "selectPrincipal",
  choices = c("a", "b", "c")
)

选择server.R就像这样

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

df会包含类似这样的内容

> 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

以上设置有效。现在说我想引入一个名为&#34; All&#34;的新单选按钮选择。我应该在filter(Principal==以上的server.R传递什么价值? dplyr中是否有通配符来过滤所有内容?或者是否有另一种方法相当于连接所有值(虽然我不能弄清楚语法)?

在某种程度上,我猜this question在RODBC上提出的问题与闪亮的多个输入相同,但我想知道dplyr是否有不同的方法。

1 个答案:

答案 0 :(得分:1)

Principal == input$selectPrincipal | input$selectPrincipal == "All"