R Shiny renderDataTable show two decimal places and center align all data

Viewed 8115

I am trying to only show two decimal places for all data in my table and align everything centrally. The first column is countries, but the rest are numbers. This is the code

output$Composite <- renderDataTable(FVI_DATA_COMPOSITE, options = list(pageLength = 15,lengthChange=FALSE))

Any idea how to do that?

Edit: This does not work.

output$Composite <- renderDataTable(FVI_DATA_COMPOSITE, 
  options = list(pageLength = 10,lengthChange=FALSE), round(FVI_DATA_COMPOSITE[3:9], digits=2)
2 Answers

The accepted answer's code pattern kept returning the following warning/error:

Warning: Error in : object of type 'closure' is not subsettable

I had to use a slightly different pattern within a Shiny app.R file:

server <- function(input, output) { 

  output$dtable <- DT::renderDataTable({
    datatable(FVI_DATA_COMPOSITE) %>% 
      formatRound(columns = c(3:9), digits = 2)
  })

}
Related