posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.9k stars 71 forks source link

Allow images to be used as column headers #418

Closed minimav closed 1 hour ago

minimav commented 3 months ago

Prework

Proposal

This can be achieved in a couple of ways already, although they both are very hacky. One is by using placeholder column names and replacing them appropriately in the HTML output created by as_raw_html with base64 encoded <img> tags (essentially the approach that is used in fmt_image).

A couple of approaches that might work for a proper implementation this:

df = pl.DataFrame([
    {"column_name": 1.0}
])

GT(df).fmt_column_header_image(
     column_name=<path to image>,
     # fmt_image kwargs
     height=...
)
df = pl.DataFrame([
    {"regular_name": 1.0, "image_column": "something"}
])

GT(df).col_labels(
    regular_name="some other name",
    # infer from Path type?
    image_column=Path(...),
)

I would be happy to try implementing something like this. Thank you 😄

jrycw commented 1 hour ago

Thank you for bringing this issue to our attention. I'll close it now, as the vals.fmt_image() function is available to achieve the desired result.