import htmltools as html
from reactable import Reactable, Column, embed_css
from reactable.data import cars_93
embed_css()
= cars_93[20:25, ["manufacturer", "model", "type", "price"]] data
Rendering cells
Using custom HTML to color text
from reactable.models import CellInfo
def fmt_cell_red(ci: CellInfo):
return html.div(ci.value.upper(), style="color: red")
Reactable(
data,={"manufacturer": Column(cell=fmt_cell_red)},
columns )
Inserting links and emoji
from reactable.models import CellInfo
import htmltools
= cars_93[:5, ["manufacturer", "model", "type", "air_bags", "price"]]
data
def render_link(ci: CellInfo) -> htmltools.Tag:
= data[ci.row_index, "manufacturer"]
manufacturer = htmltools.a(
url
ci.value,=f"https://wikipedia.org/wiki/{manufacturer}_{ci.value}",
href="blank_",
target
)
return url
Reactable(=data,
data=[
columnsid="model", cell=render_link),
Column(id="air_bags", cell=lambda ci: "❌ No" if ci.value == "None" else f"✅ Yes"),
Column(id="price", cell=lambda ci: f"${int(ci.value*1000):,}"),
Column(
], )