Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

shiny

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)
like image 661
OwlieW Avatar asked Dec 06 '22 14:12

OwlieW


1 Answers

output$Composite <- renderDataTable(datatable(FVI_DATA_COMPOSITE, 
  options = list(pageLength = 10,lengthChange=FALSE)) %>% formatRound(c(3:9), 2)

Documentation here

Edit: To center align

output$Composite <- renderDataTable(datatable(FVI_DATA_COMPOSITE, 
      options = list(pageLength = 10,lengthChange=FALSE)) %>%
      formatRound(c(3:9), 2) %>% 
      formatStyle(columns = c(3:9), 'text-align' = 'center')
like image 133
Vasim Avatar answered May 24 '23 04:05

Vasim