Iam正试图通过输入值过滤数据集。我创建了一个shiny::selectInput()
,其中有三个值可供选择。然而,无论Input取什么值,它似乎都被dyplr::filter()
忽略,而不是被dyplr::select()
忽略。这里的区别在哪里?我可以做些什么来实现我想要的,即我的数据集被shiny::selectInput()
中选择的变量正确过滤
library(shiny)
library(tidyverse)
library(reactable)
ui = fluidPage(
selectInput(inputId = "var", label = "Select", choices = c("height", "mass", "birth_year")),
reactableOutput(outputId = "table")
)
server = function(input, output, session){
output$table = renderReactable({
starwars %>%
select(input$var) %>%
filter(between(input$var, 50, 100)) %>%
reactable(data = .)
})
}
shinyApp(ui, server)
Tidy Evaluation参见Hadley Wickhams声明
library(shiny)
library(tidyverse)
library(reactable)
ui = fluidPage(
selectInput(inputId = "var", label = "Select", choices = c("height", "mass", "birth_year")),
reactableOutput(outputId = "table")
)
server = function(input, output, session){
output$table = renderReactable({
starwars %>%
select(input$var) %>%
filter(between(.data[[input$var]], 50, 100)) %>%
reactable(data = .)
})
}
shinyApp(ui, server)