gt icon indicating copy to clipboard operation
gt copied to clipboard

First look at faster interactive fmt_

Open slodge opened this issue 1 year ago • 0 comments

Summary

First trivial attempt at removing the burden of multiple render_formats calls for interactive tables.

I've tested this against some local test tables, and I've run the testthat tests - all looks OK... but I'm not sure if this change actually makes sense. I'm really unsure about the partial table build (e.g. no footnotes) that occur inside extract_cells - if this is needed then it might be better to split extract_cells into two functions?

Performance

Impact of this PR on:

# for local: devtools::load_all("../../play/gt")
library(gt)
library(tidyverse)
library(tictoc)

demo_length <- 10000
my_table <-
  tibble(
    Name = # generate random names
      stringi::stri_rand_strings(demo_length, 10),
    Population = round(runif(demo_length, 100000000, 1000000000)),
    Score = runif(demo_length, 0, 1)
  )

profvis::profvis({
  html1 <- my_table |> 
    gt() |> 
    fmt_number(columns = "Population") |>
    fmt_percent(columns = "Score") |> 
    opt_interactive() |> 
    gt:::as.tags.gt_tbl()
})    

is:

Before PR After PR
image image

Related GitHub Issues and PRs

  • Ref: #1528

Checklist

slodge avatar Jan 09 '24 11:01 slodge