I would like the behaviour of numeric values in DT
tables to be the same than in the print
output when using :
options(scipen = -1)
options(digits = 3)
cars/1000000
But whatever are the options, it seems that DT do not care about it:
I know that print
is not the same as rendering a table, but there should be a way to do it. I can play with signif
or round
to limit digits but I am losing information with very low values and this affects high values differently.
- I want to keep values as numeric so that the column can be sorted correctly.
- Values should be kept classical if only 3 digits, and scientific if more.
Here is the minimal example.
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)
Any clues ?