如何在过滤器中按升序显示值

问题描述 投票:0回答:2

我想在 dataTableOutput 中显示周过滤器,并按升序排列值。

这是ui.R

的代码
fluidPage(
  titlePanel("Delivery Assurance Matrix"),
  fluidRow(
    column(4,
          
           selectInput("week_count",
                       "Week",
                       c("All",
                         sort(unique(as.character(data$Week))))
    ))),
 DT::dataTableOutput("table")
)

这是server.R

的代码
function(input, output) {
output$table <- DT::renderDataTable(DT::datatable({
    data<-data
    if (input$week_count != "All") {
      data <- data[data$Week >= input$week_count,]
    }
    
    data
}))
  
}  

但在 UI 值中而不是在排序中 enter image description here

enter image description here

r shiny dt
2个回答
1
投票

您也可以购买

shinyWidgets
套餐,其中有
Select All
选项

library(shiny)
library(shinyWidgets)

data <- c(11,1,2,3,10,21)
ui <- fluidPage(
    titlePanel("Delivery Assurance Matrix"),
    fluidRow(
        column(4,
               pickerInput(
                   inputId = "week_count",
                   label = "Week",
                   choices = sort(data),
                   multiple = TRUE,
                   options = list(
                       `actions-box` = TRUE,
                       `deselect-all-text` = "None...",
                       `select-all-text` = "Select All",
                       `none-selected-text` = "None Selected"
                   )
               )

               )),
    DT::dataTableOutput("table")
)


server <- function(input, output) {}  

shinyApp(ui = ui, server = server)

enter image description here


0
投票

通过此更改解决了。

fluidRow(
    column(4,

           selectInput("week_count",
                       "Week",
                       c("All",
                         order(sort(unique(as.character(data$Week)))))
    ))
© www.soinside.com 2019 - 2024. All rights reserved.