Great-tables using streamlit how to

A friendly suggestion:

Please give a thought to integrate great-tables with ST

https://posit-dev.github.io/great-tables/examples/

Thanks.

2 Likes

I would love this as well.

As far as I’ve seen, exporting the GT object as html and passing it to st.html works OK.

Is there a specific case that does not work well with that method?

Code:
from great_tables import GT, html
from great_tables.data import sza
import polars as pl
import streamlit as st

st.title(
    ":balloon: Displaying a Great Table",
    help="Check `great_tables` [documentation](https://posit-dev.github.io/great-tables/reference/GT.html#great_tables.GT.as_raw_html)",
)

with st.echo(code_location="below"):
    ## Example from https://posit-dev.github.io/great-tables/examples/
    sza_pivot = (
        pl.from_pandas(sza)
        .filter((pl.col("latitude") == "20") & (pl.col("tst") <= "1200"))
        .select(pl.col("*").exclude("latitude"))
        .drop_nulls()
        .pivot(values="sza", index="month", on="tst", sort_columns=True)
    )

    table = (
        GT(sza_pivot, rowname_col="month")
        .data_color(
            domain=[90, 0],
            palette=["rebeccapurple", "white", "orange"],
            na_color="white",
        )
        .tab_header(
            title="Solar Zenith Angles from 05:30 to 12:00",
            subtitle=html("Average monthly values at latitude of 20&deg;N."),
        )
        .sub_missing(missing_text="")
        .as_raw_html()
    )

    st.html(table)

1 Like

Thanks! Very simple solution.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.