gt icon indicating copy to clipboard operation
gt copied to clipboard

`fmt_percent` does not match with `filters` in `opt_interactive`

Open jospueyo opened this issue 6 months ago • 1 comments

Description of the bug

When using fmt_percent and opt_interactive(use_filters = TRUE) in a table, the values that are filtered do not match the values shown by the table. They match the values without applying fmt_percent. That, is, if you want to filter a value of 26%, in the filter you must type 0.26. This is not very intuitive when navigating the report, especially for people that did not participate in the preparation of the report.

Describe the bug clearly and concisely.

Reproducible example

library(dplyr)
library(gt)

penguins |> 
    count(island, species) |> 
    mutate(prop_species = n / sum(n), .by = island) |> 
    gt() |> 
    fmt_percent(prop_species) |> 
    opt_interactive(use_filters = TRUE)

Expected result

The value entered in the filter should match the value shown in the table. That is, when typing 26, the rows with 26% should be filtered.

Session info

sessionInfo()
#> R version 4.5.0 (2025-04-11 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 26100)
#> 
#> Matrix products: default
#>   LAPACK version 3.12.1
#> 
#> locale:
#> [1] LC_COLLATE=Catalan_Spain.utf8  LC_CTYPE=Catalan_Spain.utf8   
#> [3] LC_MONETARY=Catalan_Spain.utf8 LC_NUMERIC=C                  
#> [5] LC_TIME=Catalan_Spain.utf8    
#> 
#> time zone: Europe/Madrid
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] gt_1.0.0    dplyr_1.1.4
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.37     R6_2.6.1          fastmap_1.2.0     tidyselect_1.2.1 
#>  [5] xfun_0.52         magrittr_2.0.3    glue_1.8.0        tibble_3.3.0     
#>  [9] knitr_1.50        pkgconfig_2.0.3   htmltools_0.5.8.1 generics_0.1.4   
#> [13] rmarkdown_2.29    lifecycle_1.0.4   xml2_1.3.8        cli_3.6.5        
#> [17] sass_0.4.10       vctrs_0.6.5       reprex_2.1.1      withr_3.0.2      
#> [21] compiler_4.5.0    tools_4.5.0       pillar_1.10.2     evaluate_1.0.3   
#> [25] yaml_2.3.10       rlang_1.1.6       fs_1.6.6

jospueyo avatar Jul 08 '25 10:07 jospueyo

Thanks for the report. This seems to be an issue upstream...

for opt_interactive(), we use reactable as a wrapper.

Here is the equivalent reactable code

library(reactable)
library(dplyr)
penguins |> 
  count(island, species) |> 
  mutate(prop_species = n / sum(n), .by = island) |> 
  reactable::reactable(
    filterable = TRUE,
    columns = list(
      prop_species = reactable::colDef(
        format = reactable::colFormat(
          percent = TRUE,
          digits = 2
        )
      )
    )
  )

I observe the same behavior. If you want, you can report it there https://github.com/glin/reactable/issues

olivroy avatar Jul 08 '25 13:07 olivroy