Hi, how do I generate a currency format in a table and get the correct sorting? Here's a minimal example:
# load some data
mydata<-mtcars[,1:3]
# make up a cost variable
mydata$price <- runif(nrow(mydata),5000,35000)
# format as dollar using scales library
library(scales)
mydata$price <- dollar(mydata$price)
# Define a server for the Shiny app
shinyServer(function(input, output) {
# Filter data based on selections
output$table <- renderDataTable({
mydata
})
})
shinyUI(
fluidPage(
# Create a new row for the table.
fluidRow(
dataTableOutput(outputId="table")
)
)
)
In the data table, price does not sort correctly when you click on the column header. The problem is that price is a character vector, so $99 > $200.
Is there an option in datatables to format with dollars?