簡體   English   中英

checkboxGroupInput過濾數據

[英]checkboxGroupInput to filter data

我無法讓我的過濾器盒實際過濾數據。 下面是數據和代碼的示例。 該框顯示正常並且可以單擊,但是選中該框不會過濾數據。

Name   Grade Test1 Test2  
Sam    1st   88    92  
Carla  2nd   82    88  
Matt   1st   90    76  
Kelsey 3rd   92    96




gradelist <- ("1st", "2nd", "3rd")

ui部分:

checkboxGroupInput("grade", "Filter by Grade", gradelist)

服務器部分:

output$gradetable <- DT::renderDataTable({  
DT::datatable(testscores[input$grade,])
})
library(shiny)
library(dplyr)
library(DT)

ui <- fluidPage(

    fluidRow(

      checkboxGroupInput("grade", "Filter by Grade", c("1st", "2nd", "3rd"), selected = "1st")

    ),
    fluidRow(
      column(12,
             dataTableOutput('gradetable')
      )
    )

)


server <- function(input, output) {

  testscores <- structure(list(Name = structure(c(4L, 1L, 3L, 2L), .Label = c("Carla", 
                                                                              "Kelsey", "Matt", "Sam"), class = "factor"), Grade = structure(c(1L, 
                                                                                                                                               2L, 1L, 3L), .Label = c("1st", "2nd", "3rd"), class = "factor"), 
                               Test1 = c(88L, 82L, 90L, 92L), Test2 = c(92L, 88L, 76L, 96L
                               )), .Names = c("Name", "Grade", "Test1", "Test2"), class = "data.frame", row.names = c(NA, 
                                                                                                                      -4L))

  # product definition
  output$gradetable <- renderDataTable({  

    testscores %>% filter(Grade == input$grade) %>% datatable

  })

}

# Run the application 
shinyApp(ui = ui, server = server)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM