Использование dplyr для фильтрации выходных данных таблицы в блестящем - PullRequest
0 голосов
/ 12 марта 2019

У меня есть таблица вывода из MySQL в блестящем.У меня есть определенные фильтры, от которых зависит вывод таблицы.Я получаю таблицу данных в качестве вывода, но она не реагирует.Я дал здесь детали интерфейса и сервера.Не могли бы вы дать мне знать, почему он не реагирует?

 unique_values2 <- sort(unique(opponents$opponent))

UI

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 = unique_values2)),

                      column(4,radioButtons("position", "Position", 
                                            choices = c(1:11),inline = TRUE)),

                      dataTableOutput("values1")
             )
)

SERVER

server <- function(input, output, session) {


 df<-dbGetQuery(mydb,"select 
 firstorsecond,position,opponent,tresult,mresult,points
 from customers where cust_id=7830")
 df  

 tablevalues1<-reactive
 ({
  firstorsecond<-as.integer(input$firstorsecond)
  position<-as.integer(input$position)
  opponent<-input$opponent  #String value
  mresult<-input$mresult   #String value
  tresult<-input$toss_result     #String value

  df %>% filter(firstorsecond %in% firstorsecond,position %in% 
  position,opponent %in% opponent,mresult %in% mresult,tresult %in% 
  tresult)
 })

 output$values1 <- renderDataTable({
 tablevalues1()
 })
}

Помощь очень ценится!Заранее спасибо!

1 Ответ

0 голосов
/ 12 марта 2019

Отредактированный код, который вы пробовали, работает:

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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...