您尝试过的已编辑代码确实有效:
tablevalues1<-reactive ({ fos<-as.integer(input$firstorsecond) pos<-as.integer(input$position) opp<-input$opponent match<-input$mresult toss<-input$tresult df %>% filter(firstorsecond %in% fos,position %in% pos, opponent %in% opp,mresult %in% match,tresult %in%toss ) })
问题是这种小数据集的过滤器太多了。条件之间的逗号意味着一个 AND 条件。它没有显示任何结果,因为没有任何匹配过滤条件。尝试使用更大的数据集或将输入与数据框中的确切行匹配。
AND
编辑:使用下面的代码和选项:1,1,mresult = Tied,opponent = A,tresult = Lost我在表输出中有一行。
library(shiny) ui <- navbarPage("Advanced", tabPanel("Page One", column(4,radioButtons("firstorsecond", "First Or Second", choices = c(1:2),selected='1')), column(4,radioButtons("tresult", "T Result", choices = list("Won" = "Won", "Lost" = "Lost"),selected="Won")), column(4,radioButtons("mresult", "Match Result", choices = list("Won" = "Won", "Lost" = "Lost", "Tied"="Tied"),selected="Won")), column(4,selectInput("opponent", "Select opponent", choices = c('A','B','C','D'))), column(4,radioButtons("position", "Position", choices = c(1:11),inline = TRUE)), dataTableOutput("values1") ) ) df <- data.frame(firstorsecond=c(1,1,2,1,2,1), position=c(1,3,5,8,9,11), opponent=unlist(strsplit('ABCADA','')), mresult=unlist(strsplit('Tied Tied Lost Tied Won Lost',' ')), tresult=unlist(strsplit('Lost Lost Lost Lost Won Lost',' ')), points=c(2,3,4,6,1,3) ) server <- function(input, output, session) { tablevalues1<-reactive ({ print(df) fos<-as.integer(input$firstorsecond) pos<-as.integer(input$position) opp<-input$opponent match<-input$mresult toss<-input$tresult print(dput(list(fos=fos,pos=pos,opp=opp,match=match,toss=toss))) df1 <- df %>% filter(firstorsecond %in% fos , position %in% pos , opponent %in% opp ,mresult %in% match , tresult %in%toss ) print(df1) df1 }) output$values1 <- renderDataTable({ tablevalues1() }) } shinyApp(ui = ui,server = server)