如何在 R Shiny 的 DataTables 中始终显示 3 个小数位? [英] How to always display 3 decimal places in DataTables in R Shiny?
本文介绍了如何在 R Shiny 的 DataTables 中始终显示 3 个小数位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的表中显示 3 个小数位的数据,但结果证明当我运行我的应用程序时它不显示 3 个小数位.虽然当我尝试与之交互时,它会显示 3 个小数位.
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?
推荐答案
您可以使用 DT::formatRound
函数.它需要列列表和位数来呈现:
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)
请记住在服务器函数中使用 DT::renderDataTable
并在 UI 中使用 DT::dataTableOutput
.
Just remember about using DT::renderDataTable
in the server function and DT::dataTableOutput
in the UI.
这篇关于如何在 R Shiny 的 DataTables 中始终显示 3 个小数位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文