glin / reactable

Interactive data tables for R
https://glin.github.io/reactable
Other
627 stars 80 forks source link

Format column of double to scientific notation #256

Open jliu215 opened 2 years ago

jliu215 commented 2 years ago

Awesome package! I have a question.

Is it possible to format a column of double to scientific notation in reachable parameters? I am looking for something like this:

reachable(data, columns = list(
    dbl_column = colDef(format = colFormat(scientific = TRUE, digit = 3)
   )
) 

The reason that I am not using format(scientific = TRUE) before passing it to reactable is because format(scientific = TRUE) converts my numbers to strings which I think fails reactable's build-in sort functionality.

thank you.

glin commented 2 years ago

Hi, scientific notation isn't supported by the built-in column formatters, but I think it's common enough that it'd make sense as a feature request.

For now, you can use a custom render function to implement your own custom formatter. If you do the formatting with a custom render function instead of modifying the data passed into reactable(), cells will appear formatted, but still be sorted on the original underlying data.