title: Keep formatting when exporting table with DT (DataTables buttons extension)
body: <p>I made a shiny app where someone uploads a file, some ratios are computed, and those ratios can be formatted using sliders for thresholds. I use <code>DT::formatStyle</code> for this and it is working really fine. As far as I understand this function, it creates a callback to handle the conditional formatting.</p>
  
  <p>Then, I want to export the data, using the buttons extension in <code>DT</code>. I want to keep the formatting when exporting to pdf or printing. It turns out that this doesn't work: the data is exported without any formatting. I tried to set <code>exportOptions(list(stripHtml = FALSE))</code>, but it still doesn't work.</p>
  
  <p>What surprises me as well, is that even when I print directly from Firefox (as File/Print... ; I have tried with Firefox only, and the app will only be run in Firefox), the color is dropped, but font weight is kept. I suspect that I may have to tweak the CSS but I do not know how to do that.</p>
  
  <p>I would like to have a way to make the pdf and/or the print "as is", the closest to what I see in the browser.
  Below is an example:</p>
  
  <pre><code>library(shiny)
  library(DT)
  library(dplyr)
  data("starwars")
  
  ui &lt;- fluidPage(title = "Ratios",
    sidebarLayout(
      sidebarPanel(width = 2,
                   actionButton("button", "Go"), # Emulates data loading
                   sliderInput("seuil_j", "Threshold J",
                               min = 0,  max = 80, value = 35, step = 0.5)),
      mainPanel( 
        fluidRow(column(width = 12,
                        DT::dataTableOutput("ratios"))))
    )
  )
  
  server &lt;- function(input, output, session) {
    donnees_ratios &lt;- reactive({
      req(input$button)
      set.seed(14)
      starwars %&gt;% 
        select(1:10) %&gt;% # DataTables is not happy with list columns
        mutate(signe = sample(c(1, -1), replace = TRUE, size = nrow(.)),
               ratio_j = signe * mass / height) %&gt;% 
        select(name, mass, height, signe, ratio_j, everything())
    })
  
    output$ratios &lt;- DT::renderDataTable({
      donnees_ratios() %&gt;% 
        creer_DT() %&gt;% 
        formatter_DT(input)
    })
  }
  
  creer_DT &lt;- function(donnees) {
    datatable(donnees, 
              rownames = FALSE, 
              class = 'cell-border stripe compact hover',
              extensions = c("Buttons"),
              options = list(
                dom = 'Blfrtip',
                buttons = list(
                  list(extend = "pdf", 
                       exportOptions = list(stripHtml = FALSE,
                                                       columns = ':visible'),
                       orientation = 'landscape'),
                  list(extend = "print", 
                       exportOptions = list(stripHtml = FALSE,
                                            columns = ':visible')),
                 "excel", "csv", "colvis"),
                language = list(
                  decimal = ",",
                  thousands = "&amp;#8239;"  # small unbreakable space
                )
              )
    )
  }
  
  formatter_DT &lt;- function(table, input) {
    table %&gt;% 
      formatPercentage(columns = c("ratio_j"),
                       digits = 1L, dec.mark = ",", mark = "&amp;#8239;") %&gt;%
      formatRound(columns = c("height", "mass"),
                  digits = 1L, dec.mark = ",", mark = "&amp;#8239;") %&gt;%
      format_seuil("ratio_j", input$seuil_j)
  }
  
  format_seuil &lt;- function(table, column, seuil) {
    # Threshold for the aboslute value, and different coloring if higher or lower
    formatStyle(table, column, 
                fontWeight = styleInterval(
                  c(-seuil / 100, seuil / 100), c("bold", "normal", "bold")),
                color = styleInterval(
                  c(-seuil / 100, seuil / 100), c("red", "black", "orange")
                ))
  }
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>I can export to pdf or print, but the display is modified. I could also generate a pdf with <code>rmarkdown</code> and <code>knitr</code>, but this would be twice the work, and it feels like I miss something using the buttons extension.</p>
  
  <p>I hope that is clear and thanks for helping!</p>
  
  <p>Florian</p>