1

I use simple code of app.R. When I launch it on my local machine and export table by xls - it's ok. By when I launch it on server and do the same - all numeric columns are characters in xls. There are error "the number in this cell is formatted as text or preceded by an apostrophe". When I copy or export by csv - it's ok. Problem only with export by xls and only on server.

Main problem is param 'mark' in FormatCurrentcy. If I set it like '.' or ',' - it's ok. But I need ' ' (space). Maybe there some settings that different on my local machine and server.

Script is attached

library(shiny)
library( DT )
library(dplyr)
# Define UI for application that creates a datatables
ui <- fluidPage(
  # Application title
  titlePanel("Download Datatable")
  # Show a plot of the generated distribution
  , mainPanel(
    DT::dataTableOutput("fancyTable")
  ) # end of main panel
  
) # end of fluid page

# Define server logic required to create datatable
server <- function(input, output) {
  output$fancyTable <- DT::renderDataTable(
    datatable( data = mtcars * 1000
               , extensions = 'Buttons'
               , options = list( 
                 dom = "Blfrtip"
                 , buttons = 
                   list("copy", list(
                     extend = "collection"
                     , buttons = c("csv", "excel")
                     , text = "Download"
                   ) ) # end of buttons customization
                 # customize the length menu
                 , lengthMenu = list( c("All") # declare values
                                      # declare titles
                 ) # end of lengthMenu customization
                 , pageLength = 10
               ) # end of options
    ) %>%  # end of datatables
    formatCurrency(interval = 3, mark = ' ', columns = 1:ncol(mtcars), currency = '', digits = 0)
  )
} # end of server
# Run the application 
shinyApp(ui = ui, server = server)
  • Probably different versions of the DT package. – Stéphane Laurent Apr 26 '21 at 13:49
  • Thank you. Actually you are right. Different versions. – Sergey Kalashnik Apr 26 '21 at 14:09
  • But... older version 0.11 - works normal on local machine, and on server (when I returned to same version) - show empty table without any data. Now on local machine and server - last version, and export numeric with mark ' ' as numeric - doesn't work any where – Sergey Kalashnik Apr 26 '21 at 14:15
  • What do you mean by "does not work"? – Stéphane Laurent Apr 26 '21 at 14:19
  • I need export numeric data with thousand mark like ' ' (space). When I use last version 0.18 - result the same on local machine and server: all numeric values with 4 and more number characters (like 1 001, 10 000 etc) after export by xlsx - transformed to columns with type 'characters' – Sergey Kalashnik Apr 26 '21 at 14:31
  • And when I use 0.11 on server (last version without that problem on local machine) - after loading table users could see message "DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter '1' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4". – Sergey Kalashnik Apr 26 '21 at 14:34
  • When I turn off formatCurrency it work ok on all versions, but data is presented without thousands separator – Sergey Kalashnik Apr 26 '21 at 14:37
  • Yes, `formatCurrency` does not control the Excel formatting. The easiest way is to use the **openxlsx** package in a `downloadHandler` (not use the datatables buttons). – Stéphane Laurent Apr 26 '21 at 16:11
  • I have a lot of datatables and developing downloadHandlers for each of them - it's not the easiest way. I have already done it for the most popular reports, but I hoped that it was temporary solution. Actually It would be not a problem, if in previous version it worked at the same way - but ealierly customers saw good formated data on shiny app and good formated columns in xls. Problems started after package updating. – Sergey Kalashnik Apr 27 '21 at 12:53
  • Lol. There are 3 ways to format the Excel export: 1) use the `customize` option of the excelHtml5 button of datatables ; 2) use the recent extension `datatables-buttons-excel-styles` ; 3) use an R package such as openxlsx and a downloadHandler. The formatXXX functions of DT have nothhing to do with the Excel formatting, and never had. Ask the developers if you don't believe me ヽ(ヅ)ノ – Stéphane Laurent Apr 28 '21 at 01:03

0 Answers0