Category
Input/Output
Scope
Minor Enhancement
Problem
I'm porting a Shiny app from R to Python, and the one thing I can't reproduce is number formatting in a table. In R I did this:
DT::datatable(dat) |>
DT::formatCurrency(
columns = c("Invoice", "MSRP"),
currency = "$",
digits = 0
)
So the grid holds real numbers, but the cells display values like $32,295.
In Python there doesn't seem to be an equivalent. DataGrid takes styles, which is great for CSS, but it only changes how a cell looks, not how the value is rendered.
Solution
What I'd love is a way to attach a display format to a column while the underlying value stays numeric, so sorting and filtering keep working. Something in the spirit of:
render.DataGrid(
df,
format={
"MSRP": "$,.0f",
"Invoice": "$,.0f",
}
)
Whatever the API ends up being, the pieces I care about are currency, thousands separators, percentages, and controlling decimal places.
Alternatives (Optional)
The workarounds I can see both give something up:
- Format the values into strings before handing them to the grid. Now sorting is lexicographic and the numeric range filter turns into a text search, which is worse for the user than the unformatted numbers were.
- Leave them as raw floats and stuff the units in the column name. Works, but 32295.0 in a table of prices looks unfinished.
Example (Optional)
Impact (Optional)
No response
Contribution? (Optional)
No, just suggesting.
Category
Input/Output
Scope
Minor Enhancement
Problem
I'm porting a Shiny app from R to Python, and the one thing I can't reproduce is number formatting in a table. In R I did this:
So the grid holds real numbers, but the cells display values like $32,295.
In Python there doesn't seem to be an equivalent. DataGrid takes styles, which is great for CSS, but it only changes how a cell looks, not how the value is rendered.
Solution
What I'd love is a way to attach a display format to a column while the underlying value stays numeric, so sorting and filtering keep working. Something in the spirit of:
Whatever the API ends up being, the pieces I care about are currency, thousands separators, percentages, and controlling decimal places.
Alternatives (Optional)
The workarounds I can see both give something up:
Example (Optional)
Impact (Optional)
No response
Contribution? (Optional)
No, just suggesting.