I would like to sort a DataTable column that is formatted with dollars (and thus is a character). I have used scales::dollar()
for formatting. This converts the field to a character which causes sorting problems (for instance, "$8" > "$10"
).
How can I sort the field as if it were numeric? Alternatively, can I keep the field as numeric and just print with dollar formatting?
app.R (requires Shiny 0.10.2)
server <- function(input, output) {
output$foo_table <- renderDataTable({
x <- seq(8000, 12000, by = 1000)
x <- scales::dollar(x)
d <- data.frame(x, stringsAsFactors = FALSE)
d
})
}
ui <- shinyUI(fluidPage(
mainPanel(dataTableOutput("foo_table"))
)
)
shinyApp(ui = ui, server = server)