Create icon ratings in GT cells using FontAwesome icons.
This function represents numeric ratings in table column(s) by displaying a row of FontAwesome icons (such as stars) in each cell. Filled icons indicate the rating value, while unfilled icons represent the remainder up to the maximum rating. Hover the icons to see the original numeric rating.
Parameters
gt:GT
A GT object to modify.
columns:SelectExpr
One or more columns containing numeric rating values.
max_rating:int=5
The maximum rating value (number of total icons).
name:str='star'
The FontAwesome icon name to use.
primary_color:str='gold'
The color for filled icons.
secondary_color:str='gray'
The color for unfilled icons.
height:int=20
The height of the rating icons in pixels.
Returns
:GT
A GT object with icon ratings added to the specified column(s).
Example
from random import randintfrom great_tables import GTfrom great_tables.data import gtcarsimport gt_extras as gtegtcars_mini = ( gtcars .loc[8:15, ["model", "mfr", "hp", "trq", "mpg_c"]] .assign(rating=[randint(1, 5) for _ inrange(8)]))gt = ( GT(gtcars_mini, rowname_col="model") .tab_stubhead(label="Car"))gt.pipe(gte.gt_fa_rating, columns="rating", name="r-project")