我有一个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
是否有不同的方法。
答案 0 :(得分:1)
Principal == input$selectPrincipal | input$selectPrincipal == "All"