如何将 `DT::renderDT()` 与 `option` 参数和 `formatCurrency()` 一起使用

How to use `DT::renderDT()` with both `option` argument and `formatCurrency()`

我使用 DT::renderDT() 在 Shiny 应用程序中显示了一个 table,如下所示:

DT::renderDT(tab %>% 
            selection = "none",
            extensions = 'Buttons',
            option = list(buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
                          dom = 'Brti')
          )

然后我也想使用 formatCurrency() 函数:

DT::renderDT(DT::datatable(tab) %>% 
              DT::formatCurrency(columns = 2:5, 
                                 currency = '',                                 
                                 mark = " ",
                                 digits = 0),
            selection = "none", 
            extensions = 'Buttons',
            option = list(buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
                          dom = 'Brti')
          )

并得到以下警告: Warning in processWidget(instance) : renderDataTable ignores ... arguments when expr yields a datatable object; see ?renderDataTable 即我不能同时提供 datatable() 对象本身和 renderDT() 选项。

很遗憾,我没有找到在DT::renderDT()函数中直接使用formatCurrency()函数的方法,谁能告诉我应该怎么做?

在这种情况下,需要在 datatable 调用中传递参数:

library(shiny)
library(DT)
library(datasets)

tab <- iris

ui <- fluidPage(DT::DTOutput("myTable"))

server <- function(input, output, session) {
  output$myTable <- DT::renderDT({
    DT::datatable(
      tab,
      selection = "none",
      extensions = 'Buttons',
      option = list(
        buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
        dom = 'Brti'
      )
    ) %>%
      DT::formatCurrency(
        columns = 2:5,
        currency = '',
        mark = " ",
        digits = 0
      )
  })
}

shinyApp(ui, server)