A lot of digits in shiny DT

Open
#1,071 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript, r

Research direction

Start by running the supplied Shiny example and inspect the datatable(), renderDT(), and replaceData() paths involved in updating the table. Compare the displayed values with the rounded dataframe values, including rows with different rounding steps; the issue is done when the table preserves the intended row-specific precision.

Written by the indexing model from the issue text.

Description

After upgrading to R version 4.3.1 and DT 0.28, in shiny DT tables sometimes have a lot of digits, but in the dataframe the number is rounded - round(x / 0.01) * 0.01
It is not suitable to set a common number of digits for all row. Each row has a unique rounding step 0.1, 0.01, 0.001...

image

ui <- fluidPage(
  actionButton(inputId = "update", label = "Update"),
  DTOutput("tbl")
)

server <- function(input, output) {
  dt_tbl <- eventReactive(
    eventExpr = input$update,
    ignoreNULL = FALSE,
    valueExpr = data.table(price = round(runif(n = 10, min = 0.8, max = 0.85) / 0.01) * 0.01))
  
  output$tbl <- renderDT(isolate(expr = {
    datatable(dt_tbl(),
              class = "cell-border stripe", extensions = "FixedHeader", selection = "none", rownames = FALSE,
              options = list(dom = "t", fixedHeader = TRUE, paging = FALSE, ordering = FALSE,
                             columnDefs = list(list(className = "dt-center", targets = "_all"))))
  }))
  
  observe(dataTableProxy("tbl") %>% replaceData(dt_tbl(), rownames = FALSE))
  
}

shinyApp(ui, server)

Stack Overflow


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.
Dominant language
JavaScript
Stars
621
Forks
177
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rstudio/DT

All issues in rstudio/DT

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.