import htmltools as html
from reactable.data import cars_93
from reactable import Reactable, Column, embed_css
embed_css()
data = cars_93[20:25, ["manufacturer", "model", "type", "price"]]Custom rendering (python)
Cells
from reactable.models import CellInfo
def fmt_cell_red(ci: CellInfo):
return html.div(ci.value.upper(), style="color: red")
Reactable(
data,
columns={"manufacturer": Column(cell=fmt_cell_red)},
)Headers
from reactable.models import HeaderCellInfo
def fmt_header(ci: HeaderCellInfo):
return html.div(f"name: {ci.name}", html.br(), f"value: {ci.value}")
Reactable(
data,
columns={"manufacturer": Column(header=fmt_header, name="Manufacturer")},
)Expandable row details
from reactable.models import RowInfo
# TODO: explain use of to_widget
def fmt_details(ci: RowInfo):
return html.div(
f"Details for row: {ci.row_index}",
Reactable(data[ci.row_index, :]).to_widget(),
)
Reactable(
data[["model"]],
details=fmt_details,
)Why use javascript? Dynamic filtering
from reactable.models import JS
js_footer = JS(
"""
function(column, state) {
let total = 0
state.sortedData.forEach(function(row) {
total += row[column.id]
})
return '<b>$' + total.toFixed(2) + '</b>'
}"""
)
Reactable(
data,
searchable=True,
columns={
"price": Column(
html=True,
footer=js_footer,
),
},
)