title: Control number formatting in Shiny's implementation of DataTable
body: <h2>Aim</h2>
  
  <p>Render large numbers as with thousands separators in a shiny DataTable by default.</p>
  
  <h2>Problem</h2>
  
  <p>The documentation reads (to me) like it should already be showing thousand separators. Am I suffering compatibility issues or do I need to add more to my code, and if so what and how?</p>
  
  <p><strong>[UPDATE]</strong> There is another <a href="https://stackoverflow.com/questions/26574939/printing-like-a-character-but-sorting-like-numeric-in-shiny-and-datatable">SO question</a> that attempts to resolve sorting of pre-formatted data in shiny. The question is unresolved but suggests another route - formatting beforehand. Is this an advisable route and if so, how to resolve correctly the other OP's issues with sorting?</p>
  
  <h2>Background</h2>
  
  <p>I am trying to improve the output of a table in shiny to improve readability. I have successfully used another <a href="https://stackoverflow.com/questions/26228786/freezing-header-and-first-column-using-data-table-in-shiny">SO question</a> to freeze the headers but am struggling to get numbers formatted correctly.</p>
  
  <h2>MWE</h2>
  
  <pre><code>library(shiny)
  runApp(
    list(ui = fluidPage(
      tagList(
        singleton(tags$head(tags$script(src='//cdn.datatables.net/fixedheader/2.1.2/js/dataTables.fixedHeader.min.js',type='text/javascript'))),
        singleton(tags$head(tags$link(href='//cdn.datatables.net/fixedheader/2.1.2/css/dataTables.fixedHeader.css',rel='stylesheet',type='text/css')))
      ), 
  
      dataTableOutput("mytable")
    )
    , server = function(input, output, session){
      output$mytable &lt;- renderDataTable(iris*1000,
                                        options = list(
                                          pageLength = 50,
                                          language.thousands=",",
                                          initComplete = I("function(settings, json){
                                            new $.fn.dataTable.FixedHeader(this, {
                                              left:   true
                                            } );
                                          }")
                                        )
      )
    })
  )
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/ZEtAY.png" alt="Example of display"></p>
  
  <h2>Documentation</h2>
  
  <p>Looking at the DataTable documentation it appears like setting the language.thousands should be sufficient:</p>
  
  <blockquote>
    <p>DataTables' built in number formatter (formatNumberDT) is used to
    format large numbers that are used in the table information.</p>
  </blockquote>
  
  <p><a href="https://datatables.net/reference/option/language.thousands" rel="noreferrer" title="language.thousands">language.thousands</a></p>
  
  <blockquote>
    <p>By default DataTables will use the character specified in
    language.thousandsDT (in turn, that, by default, is a comma) as the
    thousands separator.</p>
  </blockquote>
  
  <p><a href="https://datatables.net/reference/option/formatNumber" rel="noreferrer" title="formatNumber">formatNumber</a></p>
  
  <p>In formatNumber it has a function that could be added, however, this is very new to me so I'm unsure exactly how this function would be utilised in the context of the existing code.</p>
  
  <pre><code>$('#example').dataTable( {
    "formatNumber": function ( toFormat ) {
      return toFormat.toString().replace(
        /\B(?=(\d{3})+(?!\d))/g, "'"
      );
    };
  } );
  </code></pre>
  
  <h2>Browser details</h2>
  
  <p>Chrome: Version 39.0.2171.71 m</p>