Отредактированный код, который вы пробовали, работает:
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
.Он не показывает никаких результатов, потому что нет ни одного, соответствующего условиям фильтра.Попробуйте с большим набором данных или сопоставьте входные данные с точной строкой в вашем фрейме данных.
Редактировать: Используя приведенный ниже код и параметры: 1,1, mresult = Связанный, оппонент = A, tresult = Lost Iполучил одну строку в таблице вывода.
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)