from reactable import Reactable, Column, embed_css
from reactable.data import cars_93, starwars
embed_css()
= starwars[:5, :10] starwars_small
Table styling
Highlight rows on hover
Reactable(
starwars_small,=True,
highlight )
Bordered
Reactable(
starwars_small,=True,
bordered )
Borderless
Reactable(
starwars_small,=True,
borderless )
Outlined
Reactable(
starwars_small,=True,
outlined )
Striped
Reactable(
starwars_small,=True,
striped )
Bordered + striped + highlighting
Reactable(
starwars_small,=True,
bordered=True,
striped=True,
highlight )
Outlined + borderless
Reactable(
starwars_small,=True,
outlined=True,
borderless )
Compact
Reactable(
starwars_small,=True,
compact )
No text wrapping
import polars as pl
import polars.selectors as cs
Reactable("name", "species", "films"]],
starwars[[=False,
wrap=True,
resizable=True,
bordered=5,
default_page_size )
Column widths
Reactable(6, ["make", "type", "weight"]],
cars_93[:=[
columnsid="make", min_width=200),
Column(id="type", min_width=100),
Column(id="weight", min_width=100),
Column(
],=True,
bordered )
No full width
Reactable(6, :5],
cars_93[:=False,
full_width=True,
bordered=Column(min_width=120),
default_col_def )
You can also set a maximum or fixed width on the table:
Reactable(6, :5],
cars_93[:=False,
full_width=True,
bordered=Column(min_width=120),
default_col_def# Set a maximum width on the table
={"max-width": 650},
style# or a fixed width:
=650,
width )
Vertical alignment
from htmltools import div
from reactable.models import CellInfo
= starwars[:6, ["name", "height", "mass", "gender", "homeworld", "species"]]
data
def render_species(ci: CellInfo):
= data[ci.row_index, "species"]
species = species if species else "Unknown"
species_name return div(
="font-weight: 600"),
div(ci.value, style="font-size: 0.75rem"),
div(species_name, style
)
Reactable(
data,=[
columns
Column(id="name",
="Character / Species",
name=render_species,
cell
),id="species", show=False),
Column(
],=Column(v_align="center", header_v_align="bottom"),
default_col_def=True,
bordered )
Custom CSS
from IPython.display import display, HTML
display(
HTML("""
<style>
.my-tbl {
border: 1px solid rgba(0, 0, 0, 0.1);
}
.my-header {
border-width: 1px;
}
.my-col {
border-right: 1px solid rgba(0, 0, 0, 0.05);
}
.my-row:hover {
background-color: #f5f8ff;
}
</style>
"""
)
)
Reactable(
starwars_small,=6,
default_page_size=True,
borderless="my-tbl",
class_=Column(header_class="my-header"),
default_col_def=[
columnsid="name", class_="my-col"),
Column(
],="my-row",
row_class )