I want to export a datatable to Excel in R Shiny. For this purpose, I want to use the export button that is available in datatable. The table consists of columns formatted using formatCurrency(). Some of those columns contain a Euro-Symbol and some a percentage symbol.
However, these columns cause problems when the table is exported to Excel. In Excel, they are not numeric, but strings. But I want them to be numeric. That is, they should be arranged on the right and not on the left. But the format should not change.
Here is a an example that shows the problem:
library(shiny)
library(DT)
ui <- fluidPage(
DTOutput("table")
)
server <- function(input, output, session) {
output$table <- renderDT({
datatable(mtcars * 1000,
rownames = FALSE,
extensions = "Buttons",
options = list(
dom = "Bfrtip",
buttons = list(
list(
extend = "excel",
text = "<i class='fa fa-file-excel-o'></i> Excel",
filename = "Data",
title = NULL
)
)
)
) %>%
formatCurrency(
1:6,
currency = "\u20AC",
digits = 2,
mark = ".",
dec.mark = ",",
before = FALSE
) %>%
formatCurrency(
7:11,
currency = "\u0025",
digits = 3,
mark = ".",
dec.mark = ",",
before = FALSE
)
})
}
shinyApp(ui, server)
Please let me know, if I need to deliver further information.