import polars as pl
import htmltools as html
from reactable.data import cars_93
from reactable import Reactable, reactable, embed_css
from reactable.models import Column, ColInfo, CellInfo, HeaderCellInfo, RowInfo, JS
embed_css()
= cars_93[20:25, ["manufacturer", "model", "type", "price"]] data
Javascript formatters
Cell
= Column(
column =JS(
cell"""
function(cellInfo, state) {
// input:
// - cellInfo, an object containing cell info
// - state, an object containing the table state (optional)
//
// output:
// - content to render (e.g. an HTML string)
return `<div><b>${cellInfo.value}</b></div>`
}
"""
),=True, # to render as HTML
html
)
={"manufacturer": column}) Reactable(data, columns
cellInfo
properties
Headers
= Column(
column =JS(
header"""
function(column, state) {
// input:
// - column, an object containing column properties
// - state, an object containing the table state (optional)
//
// output:
// - content to render (e.g. an HTML string)
return `<div><em>${column.name}</em></div>`
}
"""
),=True, # to render as HTML
html
)
Reactable(
data,={"price": column},
columns )
column
properties
Expandable row details
Reactable(
data,=JS(
details"""
function(rowInfo, state) {
// input:
// - rowInfo, an object containing row info
// - state, an object containing the table state (optional)
//
// output:
// - content to render (e.g. an HTML string)
return `<div>Details for row: ${rowInfo.index}</div>`
}
"""
), )
rowInfo
properties