R Shiny renderDataTable显示两个小数位并将所有数据居中对齐

Owl*_*ieW 1 r shiny

我试图只为表中的所有数据显示两位小数,然后将所有内容集中对齐。第一列是国家,但其余是数字。这是代码

output$Composite <- renderDataTable(FVI_DATA_COMPOSITE, options = list(pageLength = 15,lengthChange=FALSE))
Run Code Online (Sandbox Code Playgroud)

任何想法如何做到这一点?

编辑:这不起作用。

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

Vas*_*sim 5

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

这里的文件

编辑:居中对齐

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')
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,但这没有用。关闭时出错 (2认同)

Bri*_*n D 5

接受的答案的代码模式不断返回以下警告/错误:

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

我不得不在 Shinyapp.R文件中使用稍微不同的模式:

server <- function(input, output) { 

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

}
Run Code Online (Sandbox Code Playgroud)