我正在尝试使用用户输入作为单选按钮来过滤数据框。不幸的是,只有一种类型的过滤器有效(在我的示例中为“年度”版本),但“每月”和“每季度”选项没有返回任何内容。这是我的示例数据集和代码。
# sample data
mydf <- data.frame("Data"=rnorm(12),
"Months"=c("Jan", "Nov", "Dec", "Feb",
"Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct"))
library(shiny)
library(dbplyr)
ui <- fluidPage(
# Input() function
radioButtons(inputId = "myDateInterval", label = "Select Date Interval",
choiceNames = list("Monthly","Quarterly","Annual"),
choiceValues = list(unique(as.character(mydf$Month)),
unique(as.character(mydf$Month))
[seq(1,length(unique(mydf$Month)),3)],
unique(as.character(mydf$Month)[1]))),
# Output() functions
tableOutput("results"))
# set up server object
server <- function(input, output) {
output$results <- renderTable({
mydf %>% filter(Months %in% input$myDateInterval)
})
}
shinyApp(ui = ui, server = server)