2017-06-01 38 views
0

我想只显示我的表中的所有数据的两位小数,并集中对齐所有内容。第一列是国家,其余是数字。这是密码R闪亮renderDataTable显示两位小数,并居中对齐所有数据

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

任何想法该怎么做?

编辑:这不起作用。

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

你可以使用'round'功能圆的数据。 – SBista

+0

我想我试过,但无法得到它的工作。你会如何建议实施它? – OwlieW

回答

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

Documentation here

编辑:中心对齐

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') 
+0

谢谢,但没有奏效。关闭时发生错误 – OwlieW

+0

答案更新后,请检查 – Vasim

+0

这很有效,非常感谢。最后一件事,你知道如何在舍入发生的同一列中对齐所有数据吗? – OwlieW