如何在R Shiny中始终显示DataTables中的3位小数位? [英] How to always display 3 decimal places in DataTables in R Shiny?

查看:308
本文介绍了如何在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.

有没有办法这样做?

推荐答案

您可以使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆