This is a follow up question to this inquiry: Adding Total/Subtotal to the bottom of a DataTable in Shiny. Below is the code snippet referenced:
library(shiny)
library(DT)
ui <- shinyUI(fluidPage(
h1('Testing TableTools'),
mainPanel(
dataTableOutput('display')
)
))
Names <- c("",names(mtcars))
FooterNames <- c(rep("",4),Names[5:6],rep("",6))
server <- function(input, output, session) {
sketch <- htmltools::withTags(table(
tableHeader(Names),tableFooter(FooterNames)
))
opts <- list(
dom = 'Bfrtip', buttons = list('colvis','print',list(extend='collection',text='Download',buttons = list('copy','csv','excel','pdf'))),
footerCallback = JS(
"function( tfoot, data, start, end, display ) {",
"var api = this.api(), data;",
"$( api.column(5).footer()).html('SubTotal: '+",
"api.column(5).data().reduce( function ( a, b ) {",
"return a + b;",
"} )",
");",
"$( api.column(4).footer()).html('SubTotal: '+",
"api.column(4).data().reduce( function ( a, b ) {",
"return a + b;",
"} )",
");","}")
)
output$display <- DT::renderDataTable(container = sketch,extensions = 'Buttons',options = opts,{
mtcars
})
}
shinyApp(ui = ui, server = server)
When displaying subTotal in the dataframe, it presents the numbers with more than two digits after the decimal point, such as 1234,51999999999 instead of 1234,52.
To rectify this issue, what changes need to be made in the Javascript code to only display two digits after the decimal point, use a dot as a thousands separator, a comma as a decimal point, and also include a Euro (€) symbol next to the sum?