将逗号添加到闪亮的renderDataTable中的每个数字

时间:2018-10-31 13:48:43

标签: r datatable shiny

我想在数据库中以逗号分隔显示大量数字。我该如何在Shiny应用程序的renderDataTable函数中包含格式货币子句以实现此目的?

This帖子介绍了如何将其添加到常规DT中,但是我正在将数据表提供给UI。我认为货币不是options之一。

output$dummy_data_table <- DT::renderDataTable(
    data.frame(A=c(1000000.51,5000.33, 2500, 251), B=c(0.565,0.794, .685, .456)),
    extensions = 'Buttons',
    server=FALSE,
    options = list(
      pageLength = 50,
      scrollX=TRUE,
      dom = 'T<"clear">lBfrtip',
    )  # close options
  ) # close renderDataTable

1 个答案:

答案 0 :(得分:2)

关注我的评论-

shinyApp(
  ui = fluidPage(
    DTOutput("dummy_data_table")
  ),
  server = function(input, output) {
    output$dummy_data_table <- DT::renderDataTable(
      data.frame(A=c(1000000.51,5000.33, 2500, 251), B=c(0.565,0.794, .685, .456)) %>%
        datatable(extensions = 'Buttons',
          options = list(
            pageLength = 50,
            scrollX=TRUE,
            dom = 'T<"clear">lBfrtip'
          )
        ) %>%
        formatCurrency(1:2, currency = "", interval = 3, mark = ",")
    ) # close renderDataTable
  }
)