【发布时间】:2015-05-28 00:41:25
【问题描述】:
我希望在闪亮的应用程序中将变量名称传递给 dplyr 时,有人可以帮助我进行非标准评估。我的意图是能够选择要传递给函数select 和top_n 的变量。我知道 select 函数有一个等效的 select_ 用于 NSE,但我也在努力让它在闪亮的应用程序中工作。
我在下面包含了一个示例,其中有两行注释行,这些行是我希望开始工作的。第一个注释行旨在从输出表中删除由input$var_to_rank 标识的列,而第二个注释行(使用top_n)应设置要显示的排名靠前的行数,以及这些排名所基于的列。
library(shiny)
library(dplyr)
data(iris)
shinyApp(
ui = basicPage(
selectInput("species", "species", choices = levels(iris$Species)),
selectInput("var_to_drop", "Variable to drop", choices = names(iris)[3:4]),
selectInput("var_to_rank", "Variable to rank", choices = names(iris)[1:2]),
numericInput("n.obs", "Top N", 5),
tableOutput("table")
),
server = function(input, output) {
output$table <- renderTable({
iris %>%
filter(Species == input$species) %>%
# select_(quote(-input$var_to_drop)) %>%
top_n(5, Sepal.Length)
# top_n(n.obs, input$var_to_rank)
})
}
)
如果这个问题在别处得到解答,非常感谢您的帮助和道歉。
【问题讨论】:
-
对第一条评论的简单修复是使用
get--select(-get(input$var_to_drop)) -
谢谢杰森。你是对的。我曾尝试
get和top_n失败并放弃了它,但它适用于select。我还尝试将top_n的使用替换为filter_(min_rank(desc(input$var_to_rank)) <= input$n.obs),但这也不起作用。也没有与get一起采用这种方法。