DT::datatable() is a great way to show interactive tables in RMarkdown documents.
(Unfortunately it’s a little bit tricky to use them with blogdown in combination
with some hugo themes. But that’s another story.)
The user can sort any column as he wants to. But it’s an English tool. Numbers are formated in the American or English way: As decimal mark a point is used and between thousands a comma is used as separator. So it’s $ 1,234,567.89 $
In Germany both characters are switched: It’s $ 1.234.567,89 $.
You can format columns in
DT::datatable() using the function
But this breaks the sorting. Let’s have a look.
First load the libraries.
## Loading required package: htmlwidgets
widgetframe is used to embed the the table.
That’s the simple output with English formatting:
I’ve added the column
example so we can test negative numbers and numbers which
absolute values has one (0 - 999,999) or two thousend-delimeters (1,000,000 - 999,999,999).
example is okay.
When you try to sort this table along the column
example you’ll see that the
ordering is wrong.
language option (see line 5 below) solves our problem:
Now you can order along