R DataTable:如何格式化一列以逗号表示数字?

R DataTable:如何格式化一列以逗号表示数字?,r,shiny,dt,R,Shiny,Dt,在Shiny内部,我正在呈现一个数据表 我正在阅读DT包的选项,我发现要做到这一点,我需要了解Javascript 我对JS了解不多,所以我要问这个问题。我现在最大的数字是:22381,最小的是0 我想将:22381显示为22381。如果可能:22381作为S/.22381。 这就是我的DataTable现在呈现的方式,我正在使用选项来订购(描述)收入 output$products <- renderDataTable(products_ss(),

在Shiny内部,我正在呈现一个数据表

我正在阅读DT包的选项,我发现要做到这一点,我需要了解Javascript

我对JS了解不多,所以我要问这个问题。我现在最大的数字是:22381,最小的是0

我想将:22381显示为22381。如果可能:22381作为S/.22381。

这就是我的DataTable现在呈现的方式,我正在使用选项来订购(描述)收入

output$products <- renderDataTable(products_ss(),
                                           options = list(
                                             order = list(list(2, 'desc'))
                                           ))

我已更改您的答案以匹配我的列名。

您正在查找
DT::formatCurrency

library(DT)
datatable(m) %>% 
             formatCurrency(c('V1', 'V2', 'V3', 'V4', 'V5'), currency = ' S/.',
                            interval = 3, mark = ',', before = FALSE)
更新1:
库(闪亮)
图书馆(DT)
#使用DT::dataTableOutput和DT::renderDataTable,因为它们也有这些函数名
shinyApp(
ui=fluidPage(fluidRow(第12列,DT::dataTableOutput('tbl')),
服务器=功能(输入、输出){

m您正在寻找
DT::formatCurrency

library(DT)
datatable(m) %>% 
             formatCurrency(c('V1', 'V2', 'V3', 'V4', 'V5'), currency = ' S/.',
                            interval = 3, mark = ',', before = FALSE)
更新1:
库(闪亮)
图书馆(DT)
#使用DT::dataTableOutput和DT::renderDataTable,因为它们也有这些函数名
shinyApp(
ui=fluidPage(fluidRow(第12列,DT::dataTableOutput('tbl')),
服务器=功能(输入、输出){

m没有Javascript的选项可能会将列转换为使用
scales::comma()
[1]“22381”
没有Javascript的选项可能会将列转换为使用
scales::comma()
[1]“22381”
Ty,我尝试过你的答案,但它给了我一个错误,请参阅我的更新。请你解释一下如何在闪亮的渲染函数中应用
formatCurrency
?也许你还可以帮助回答另一个问题:谢谢,它按预期工作。但现在我已经失去了第二列的降序。我不知道如何%>%o选项列表中的选项。可以扩展该部分吗,请参见。Ty,我尝试过你的回答,但它给我一个错误,请参阅我的更新。可以解释如何在闪亮的渲染函数中应用
formatCurrency
吗?也许你还可以帮助回答另一个问题:谢谢,它按预期工作。但现在我已经失去了第二列。我不知道如何%>%在选项列表中导入该选项。请您扩展该部分。
library(DT)
datatable(m) %>% 
             formatCurrency(c('V1', 'V2', 'V3', 'V4', 'V5'), currency = ' S/.',
                            interval = 3, mark = ',', before = FALSE)
library(shiny)
library(DT)
#Use DT::dataTableOutput and DT::renderDataTable as shiny also has these functions name
shinyApp(
  ui = fluidPage(fluidRow(column(12, DT::dataTableOutput('tbl')))),
  server = function(input, output) {
    m <- reactive({m <- as.data.frame(matrix(round(rnorm(100, 1e5, 1e6)), 20))})
    output$tbl = DT::renderDataTable(
      datatable(m()) %>% formatCurrency(c('V1', 'V2', 'V3', 'V4', 'V5'), currency = ' S/.',
                                           interval = 3, mark = ',', before = FALSE) 
    )
  }
)