-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add 2 great tables to examples page
- Loading branch information
Showing
5 changed files
with
167 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
pagetitle: coffee table | ||
navbar: false | ||
--- | ||
|
||
:::{.shrink-example} | ||
|
||
```{python} | ||
#| echo: false | ||
# NOTE: I can't get quarto embed to work with the great-tables.qmd, | ||
# so have just copied in the example code here :/ | ||
import os | ||
os.chdir("..") | ||
from reactable import embed_css, render | ||
embed_css() | ||
import polars as pl | ||
import polars.selectors as cs | ||
from great_tables import GT, loc, style | ||
coffee_sales = pl.DataFrame.deserialize("coffee-sales/coffee-sales.json", format="json") | ||
sel_rev = cs.starts_with("revenue") | ||
sel_prof = cs.starts_with("profit") | ||
coffee_table = ( | ||
GT(coffee_sales) | ||
.tab_header("Sales of Coffee Equipment") | ||
.tab_spanner(label="Revenue", columns=sel_rev) | ||
.tab_spanner(label="Profit", columns=sel_prof) | ||
.cols_label( | ||
revenue_dollars="Amount", | ||
profit_dollars="Amount", | ||
revenue_pct="Percent", | ||
profit_pct="Percent", | ||
monthly_sales="Monthly Sales", | ||
icon="", | ||
product="Product", | ||
) | ||
# formatting ---- | ||
.fmt_number( | ||
columns=cs.ends_with("dollars"), | ||
compact=True, | ||
pattern="${x}", | ||
n_sigfig=3, | ||
) | ||
.fmt_percent(columns=cs.ends_with("pct"), decimals=0) | ||
# style ---- | ||
.tab_style( | ||
style=style.fill(color="aliceblue"), | ||
locations=loc.body(columns=sel_rev), | ||
) | ||
.tab_style( | ||
style=style.fill(color="papayawhip"), | ||
locations=loc.body(columns=sel_prof), | ||
) | ||
.tab_style( | ||
style=style.text(weight="bold"), | ||
locations=loc.body(rows=pl.col("product") == "Total"), | ||
) | ||
.fmt_nanoplot("monthly_sales", plot_type="bar") | ||
.fmt_image("icon", path="coffee-sales") | ||
.sub_missing(missing_text="") | ||
) | ||
# coffee_table.save("data/coffee-table.png", scale=2) | ||
render(coffee_table) | ||
``` | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
pagetitle: solar zenith angles | ||
navbar: false | ||
--- | ||
|
||
:::{.shrink-example} | ||
|
||
```{python} | ||
# | echo: false | ||
from reactable import embed_css, render | ||
embed_css() | ||
from great_tables import GT, html | ||
from great_tables.data import sza | ||
import polars as pl | ||
import polars.selectors as cs | ||
sza_pivot = ( | ||
pl.from_pandas(sza) | ||
.filter((pl.col("latitude") == "20") & (pl.col("tst") <= "1200")) | ||
.select(pl.col("*").exclude("latitude")) | ||
.drop_nulls() | ||
.pivot(values="sza", index="month", on="tst", sort_columns=True) | ||
) | ||
gt = ( | ||
GT(sza_pivot, rowname_col="month") | ||
.data_color( | ||
domain=[90, 0], | ||
palette=["rebeccapurple", "white", "orange"], | ||
na_color="white", | ||
) | ||
.tab_header( | ||
title="Solar Zenith Angles from 05:30 to 12:00", | ||
subtitle=html("Average monthly values at latitude of 20°N."), | ||
) | ||
.cols_width({k: 50 for k in sza_pivot.columns}) | ||
.sub_missing(missing_text="") | ||
) | ||
render(gt) | ||
``` | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters