This post demonstrates that Polars, Great Tables, and marimo can successfully run within a Quarto environment (as shown in this post). The example uses a table styler selector from Great Tables—and I’m honestly surprised it works!
marimo
The widgets may take a few moments to load, as they rely on WebAssembly under the hood.
import%20marimo%20as%20mo%0Aimport%20polars%20as%20pl%0Afrom%20great_tables%20import%20GT%2C%20loc%2C%20style
data%20%3D%20%7B%0A%20%20%20%20%22col1%22%3A%20%5B2%2C%205%2C%207%2C%2010%2C%2015%5D%2C%0A%20%20%20%20%22col2%22%3A%20%5B%22x%22%2C%20%22y%22%2C%20%22y%22%2C%20%22z%22%2C%20%22z%22%5D%2C%0A%20%20%20%20%22color%22%3A%20%5B%22lightgrey%22%2C%20%22lightblue%22%2C%20%22lightblue%22%2C%20%22papayawhip%22%2C%20%22papayawhip%22%5D%2C%0A%7D%0Adf%20%3D%20pl.DataFrame(data)%0Aprint(df)
style_widget%20%3D%20mo.ui.slider(1%2C%206%2C%20label%3D%22Select%20Style%20Number%22)%0Amo.output.append(style_widget)%0A%0A_colors%20%3D%20%5B%22blue%22%2C%20%22cyan%22%2C%20%22pink%22%2C%20%22green%22%2C%20%22red%22%2C%20%22gray%22%5D%0Acolor_widget%20%3D%20mo.ui.radio(%0A%20%20%20%20options%3D_colors%2C%20value%3D_colors%5B0%5D%2C%20label%3D%22Select%20Style%20Color%22%0A)%0Amo.output.append(color_widget)%0A%0Arow_striping_widget%20%3D%20mo.ui.switch(value%3DTrue%2C%20label%3D%22Add%20Row%20Striping%3F%22)%0Amo.output.append(row_striping_widget)
GT(df).opt_stylize(%0A%20%20%20%20style%3Dstyle_widget.value%2C%0A%20%20%20%20color%3Dcolor_widget.value%2C%0A%20%20%20%20add_row_striping%3Drow_striping_widget.value%2C%0A)
Check out the full marimo code below.
Show full code
import marimo
__generated_with = "0.13.15"
app = marimo.App(width= "medium" )
@app.cell
def _():
import marimo as mo
import polars as pl
from great_tables import GT, loc, style
return GT, mo, pl
@app.cell
def _(pl):
data = {
"col1" : [2 , 5 , 7 , 10 , 15 ],
"col2" : ["x" , "y" , "y" , "z" , "z" ],
"color" : ["lightgrey" , "lightblue" , "lightblue" , "papayawhip" , "papayawhip" ],
}
df = pl.DataFrame(data)
return (df,)
@app.cell
def _(mo):
style_widget = mo.ui.slider(1 , 6 , label= "Select Style Number" )
mo.output.append(style_widget)
_colors = ["blue" , "cyan" , "pink" , "green" , "red" , "gray" ]
color_widget = mo.ui.radio(
options= _colors, value= _colors[0 ], label= "Select Style Color"
)
mo.output.append(color_widget)
row_striping_widget = mo.ui.switch(value= True , label= "Add Row Striping?" )
mo.output.append(row_striping_widget)
return color_widget, row_striping_widget, style_widget
@app.cell
def _(GT, color_widget, df, row_striping_widget, style_widget):
GT(df).opt_stylize(
style= style_widget.value,
color= color_widget.value,
add_row_striping= row_striping_widget.value,
)
return
if __name__ == "__main__" :
app.run()
This post was drafted by me, with AI assistance to refine the content.