1

我使用 app.R 的简单代码。当我在本地机器上启动它并通过 xls 导出表时 - 没关系。当我在服务器上启动它并执行相同操作时 - 所有数字列都是 xls 中的字符。出现错误“此单元格中的数字格式为文本或前面带有撇号”。当我通过 csv 复制或导出时 - 没关系。仅在通过 xls 导出且仅在服务器上存在问题。

主要问题是 FormatCurrentcy 中的参数“标记”。如果我将其设置为“。” 或 ',' - 没关系。但我需要''(空格)。也许我的本地机器和服务器上有一些不同的设置。

附上脚本

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)
4

0 回答 0