I am having trouble with DT::rednerDataTable. When my datatable is produced I have three (of 10) columns of numbers that are not getting sorted. This is what it looks like sorted:
Here is my code:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardBody(
tabItems((tabName = "ResultsTable",
fluidPage(column(11, DT::dataTableOutput("table",width = "100%"),offset = 0))))
shinyServer(function(input, output, session) {
output$table <- DT::renderDataTable(DT::datatable({
data <- rv$data
if (input$sour != "All") {
data <- data[data[,1] == input$sour,]
}else{data}
if (input$sour1 != "All") {
data <-data[data[,2] == input$sour1,]
}else{data}
if (input$tran2 != "All") {
data <-data[data[,3] == input$tran2,]
}else{data}
}))
})
The variable data is a data.frame and the numeric columns are already sorted, but as I click the up and down arrows next to the column name in the table ( as shown below) the sorting gets mixed up.
I'd appreciate any help!
Thank you
as.numeric(col)
or - if they were a factor - (as.numeric(as.character(col))
– Mike Wise