25

I need to display the data in my table for 3 decimal places but it turns out that it doesn't display 3 decimal places when I run my application. Though when I try to interact with it it displays 3 decimal places.

Is there any way to do this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Achilles Ebron
  • 269
  • 1
  • 3
  • 3
  • 1
    try `options(digits = 3)` ; I would just use the answer from here: http://stackoverflow.com/questions/28033941/displaying-datatable-column-values-in-dollars-in-shiny-r?rq=1 and combine it with a `format` or `print` statement which can include the number of digits to use – grrgrrbla Jun 24 '15 at 09:17
  • If you want this post to be useful to others, please modify it by including your code. I down-voted your post but will reverse it if you address this issue. – Davit Sargsyan May 09 '19 at 22:00

1 Answers1

47

You can use DT::formatRound function. It take list of columns and number of digits to render:

library(DT)

set.seed(323)
data.frame(x=runif(10), y=rnorm(10), z=rpois(10, 1)) %>%
    datatable() %>%
    formatRound(columns=c('x', 'y'), digits=3)

enter image description here

Just remember about using DT::renderDataTable in the server function and DT::dataTableOutput in the UI.

zero323
  • 322,348
  • 103
  • 959
  • 935