title: Shiny DataTable sum of a column
body: <p>I have two character columns and one numerical column and I am trying to calculate the sum of that numerical column. I tried emulating <a href="https://stackoverflow.com/questions/49135787/total-of-a-column-in-dt-datatables-in-shiny">this</a> answer in my app but it is not working.</p>
  
  <pre><code>#here's my data
  stack_qn &lt;- structure(list(country = c("Country1", "Country3", "Country2", 
  "Country4", "Country9", "Country1", "Country2", "Country2", "Country8", 
  "Country2", "Country5", "Country6", "Country5", "Country7", "Country9", 
  "Country5", "Country3", "Country6", "Country4", "Country5"), 
      `2012` = c(0, 89, 0, 0, 0, 7, 0, 1, 0, 0, 0, 0, 0, 42, 60, 
      0, 0, 53, 213, 0), `Types of product` = c("product1", "product1", 
      "product1", "product1", "product1", "product2", "product2", 
      "product3", "product3", "product4", "product4", "product4", 
      "product6", "product6", "product6", "product7", "product7", 
      "product7", "product8", "product8")), class = c("spec_tbl_df", 
  "tbl_df", "tbl", "data.frame"), row.names = c(NA, -20L), spec = structure(list(
      cols = list(country = structure(list(), class = c("collector_character", 
      "collector")), `2012` = structure(list(), class = c("collector_double", 
      "collector")), `Types of product` = structure(list(), class = c("collector_character", 
      "collector"))), default = structure(list(), class = c("collector_guess", 
      "collector")), skip = 1), class = "col_spec"))
  
  #here's what I tried
  library(shiny)
  library(DT)
  
  
  jsCode &lt;- "function(row, data, start, end, display) {var api = this.api(), data;$( api.column(1).footer() ).html('Total: ' + MYTOTAL);}"
  
  # Workaround
  getTotal &lt;- function(data,index){
  
    if(index &lt; 1 || index &gt; ncol(data)){
      return("")
    }
    col &lt;- data[,index]
    col &lt;- gsub("[$]","",col)
    col &lt;- gsub("[,]","",col)
    col &lt;- suppressWarnings(as.numeric(col))
    if(all(is.na(col))){
      return("")
    }
    sum(col)
  }
  
  
  ui &lt;- function(){
    fluidPage(
      sidebarLayout(
        sidebarPanel(numericInput("nums", label = "Num Input", value = 1, min = 1, max = 10)),
        mainPanel(dataTableOutput("mytable"))
      )
    )
  }
  
  server &lt;- function(input, output, session){
  
    Total &lt;- reactive({
      getTotal(stack_qn,2)
    })
  
    cont &lt;- htmltools::withTags(table(
      tableHeader(names(stack_qn)),tableFooter(names(stack_qn))
    ))
  
    output$mytable &lt;- DT::renderDataTable(  {
      jsCode &lt;- sub("MYTOTAL",Total(),jsCode)
      DT::datatable(stack_qn,
                    container = cont,
                    caption = tags$caption("Example"), 
                    filter = "none", 
                    rownames = F,
                    options = list(autoWidth = T, 
                                   pageLength = 10, 
                                   scrollCollapse = T,
                                   dom = 'lftp', 
                                   footerCallback = JS(jsCode))
      )
    }
    )
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>When I run the app, nothing happens. Any help on how to get the sum of that numerical column to show is greatly appreciated.</p>