Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
Cambiar la salida de la suma de la columna de la tabla de datos brillante

Esta es una pregunta de seguimiento a esta pregunta: Agregar Total/Subtotal al final de un DataTable en Shiny con el siguiente fragmento de código:

 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)

En mi marco de datos tengo columnas que contienen dobles con dos dígitos después de la coma. El subtotal se muestra como algo como esto:

1234,51999999999 en lugar de 1234,52.

¿Qué tengo que cambiar en el código de Javascript para obtener solo dos dígitos después de la coma, los separadores de miles como un punto y el punto decimal como una coma y también, un símbolo de Euro (€) al lado de la suma?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

¿Por qué quieres hacer esto en JavaScript si estás usando shiny? Esta es la forma R:

 paste0( formatC(1234.51999999999, format="f", big.mark=".", decimal.mark = ",", digits=2), "€" ) # [1] "1.234,52€"

O use JS para hacer el trabajo:

 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; var sum1 = api.column(5).data().reduce(function(a, b) { return a + b; }); sum1 = Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(sum1) $(api.column(5).footer()).html('SubTotal: ' + sum1) } " ) ) output$display <- DT::renderDataTable(container = sketch, extensions = "Buttons", options = opts, { mtcars }) } shinyApp(ui = ui, server = server)

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!