Styling
Python
Styling with tab_style()
Add an ‘aliceblue’ background to columns pertaining to revenue.
R Code
gt_tbl_7 <-
gt_tbl_6 |>
tab_style(
style = cell_fill(color = "aliceblue"),
locations = cells_body(columns = starts_with("revenue"))
)
gt_tbl_7
_webr_editor_2 = Object {code: null, options: Object, indicator: Ke}
gt_tbl_7 = (
gt_tbl_6 \
.tab_style(style=style.fill(color="aliceblue"),
locations=loc.body(columns=["revenue_dollars", "revenue_pct"])
)
)
gt_tbl_7
Sales of Coffee Equipment | ||||
---|---|---|---|---|
Product | Revenue | Profit | ||
Amount | Percent | Amount | Percent | |
Grinder | $904,500 | 3% | $567,960 | 4% |
Moka pot | $2,045,250 | 7% | $181,080 | 1% |
Cold brew | $288,750 | 1% | $241,770 | 2% |
Filter | $404,250 | 1% | $70,010 | 0% |
Drip machine | $2,632,000 | 9% | $1,374,450 | 9% |
AeroPress | $2,601,500 | 9% | $1,293,780 | 9% |
Pour over | $846,000 | 3% | $364,530 | 2% |
French press | $1,113,250 | 4% | $748,120 | 5% |
Cezve | $2,512,500 | 9% | $1,969,520 | 13% |
Chemex | $3,137,250 | 11% | $817,680 | 6% |
Scale | $3,801,000 | 13% | $2,910,290 | 20% |
Kettle | $756,250 | 3% | $617,520 | 4% |
Espresso Machine | $8,406,000 | 29% | $3,636,440 | 25% |
Total | $29,448,500 | 100% | $14,793,150 | 100% |
Add an ‘papayawhip’ background to columns pertaining to profit.
R Code
gt_tbl_8 <-
gt_tbl_7 |>
tab_style(
style = cell_fill(color = "papayawhip"),
locations = cells_body(columns = starts_with("profit"))
)
gt_tbl_8
_webr_editor_4 = Object {code: null, options: Object, indicator: Ke}
gt_tbl_8 = (
gt_tbl_7
.tab_style(
style=style.fill(color="papayawhip"),
locations=loc.body(columns=["profit_dollars", "profit_pct"])
)
)
gt_tbl_8
Sales of Coffee Equipment | ||||
---|---|---|---|---|
Product | Revenue | Profit | ||
Amount | Percent | Amount | Percent | |
Grinder | $904,500 | 3% | $567,960 | 4% |
Moka pot | $2,045,250 | 7% | $181,080 | 1% |
Cold brew | $288,750 | 1% | $241,770 | 2% |
Filter | $404,250 | 1% | $70,010 | 0% |
Drip machine | $2,632,000 | 9% | $1,374,450 | 9% |
AeroPress | $2,601,500 | 9% | $1,293,780 | 9% |
Pour over | $846,000 | 3% | $364,530 | 2% |
French press | $1,113,250 | 4% | $748,120 | 5% |
Cezve | $2,512,500 | 9% | $1,969,520 | 13% |
Chemex | $3,137,250 | 11% | $817,680 | 6% |
Scale | $3,801,000 | 13% | $2,910,290 | 20% |
Kettle | $756,250 | 3% | $617,520 | 4% |
Espresso Machine | $8,406,000 | 29% | $3,636,440 | 25% |
Total | $29,448,500 | 100% | $14,793,150 | 100% |
Make the text bold in the bottom row (the totals column).
R Code
gt_tbl_9 <-
gt_tbl_8 |>
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(rows = product == "Total")
)
gt_tbl_9
_webr_editor_6 = Object {code: null, options: Object, indicator: Ke}
gt_tbl_9 = (
gt_tbl_8
.tab_style(
style=style.text(weight="bold"),
locations=loc.body(rows=lambda D: D["product"] == "Total")
)
)
gt_tbl_9
Sales of Coffee Equipment | ||||
---|---|---|---|---|
Product | Revenue | Profit | ||
Amount | Percent | Amount | Percent | |
Grinder | $904,500 | 3% | $567,960 | 4% |
Moka pot | $2,045,250 | 7% | $181,080 | 1% |
Cold brew | $288,750 | 1% | $241,770 | 2% |
Filter | $404,250 | 1% | $70,010 | 0% |
Drip machine | $2,632,000 | 9% | $1,374,450 | 9% |
AeroPress | $2,601,500 | 9% | $1,293,780 | 9% |
Pour over | $846,000 | 3% | $364,530 | 2% |
French press | $1,113,250 | 4% | $748,120 | 5% |
Cezve | $2,512,500 | 9% | $1,969,520 | 13% |
Chemex | $3,137,250 | 11% | $817,680 | 6% |
Scale | $3,801,000 | 13% | $2,910,290 | 20% |
Kettle | $756,250 | 3% | $617,520 | 4% |
Espresso Machine | $8,406,000 | 29% | $3,636,440 | 25% |
Total | $29,448,500 | 100% | $14,793,150 | 100% |
Downloading webR