0

I would like to display large numbers with comma separation in a datable. How would I include the format currency clause in the renderDataTable function in a Shiny app in order to do this?

This post shows how to do add it to a regular DT, but I'm feeding the datatable into the UI. I don't see currency as one of the 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
matsuo_basho
  • 2,833
  • 8
  • 26
  • 47
  • The post you shared answers your question. You'll use `formatCurreny()`. Why doesn't that work for you? – Shree Oct 31 '18 at 14:33
  • Because you can't pipe a shiny render function – matsuo_basho Oct 31 '18 at 15:27
  • Possible duplicate of [Add comma to numbers every three digits in datatable (R)](https://stackoverflow.com/questions/29242011/add-comma-to-numbers-every-three-digits-in-datatable-r) – Shree Oct 31 '18 at 15:43
  • you don't need to pipe the render function...just use `DT::datatable` and apply `formatCurrency` for that inside your render function. – Shree Oct 31 '18 at 15:45
  • Shree, please write how you would include the formatCurrency in my example above. Thanks – matsuo_basho Oct 31 '18 at 17:26

1 Answers1

2

Following up on my comments -

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
  }
)
Shree
  • 10,835
  • 1
  • 14
  • 36
  • thanks for the detailed post. Your example obviously works. If I substitute this into my actual app, with the formatCurrency (and preceding pipe) commented out, the table renders. However, when I insert it back in, the headings render, but there's a 'Processing' message on the screen in the background. Any thoughts? – matsuo_basho Nov 01 '18 at 13:29
  • to add more color, that 'Processing' message just hangs – matsuo_basho Nov 01 '18 at 14:35