rshinydt

How to display values in filter with ascending order


I want to display filter of week in dataTableOutput with value in ascending order.

Here is the code of 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")
)

Here is the code of 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
}))
  
}  

But in UI Values not in ordering enter image description here

enter image description here


Solution

  • Its solved by this changes.

    fluidRow(
        column(4,
    
               selectInput("week_count",
                           "Week",
                           c("All",
                             order(sort(unique(as.character(data$Week)))))
        ))