我想要数值的行为DT
表与表中的相同print
使用时的输出:
options(scipen = -1)
options(digits = 3)
cars/1000000
But whatever are the options, it seems that DT do not care about it:
我知道print
与渲染表格不同,但应该有一种方法可以做到。我可以玩signif
or round
限制数字,但我正在丢失非常低值的信息,这对高值的影响不同。
- 我想将值保留为数字,以便可以正确对列进行排序。
- 如果只有 3 位数字,则值应保持经典,如果更多,则应保持科学。
这是最小的例子。
library(shiny)
library(DT)
library(dplyr)
options(scipen = -1)
options(digits = 3)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
),
# Show a plot of the generated distribution
mainPanel(
DTOutput("dt"),
DTOutput("dt2")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$dt <- renderDT({cars/1000000})
output$dt2 <- renderDT({
mutate_all(cars/1000000, funs(signif(., digits = 1)))
})
}
# Run the application
shinyApp(ui = ui, server = server)
有什么线索吗?
The DT
包还有一个格式Signif() https://rdrr.io/cran/DT/man/formatCurrency.html可以帮助解决此问题的函数,例如:
output$tbl <- renderDataTable({
DT::datatable(dat) %>%
formatSignif(columns = c('speed', 'dist'), digits = 3)
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)