Displaying a Table in Streamlit
Streamlit provides the st.table()
function to display static, non-interactive tables. This is useful for presenting small datasets where interactivity is not required.
Basic Example
import streamlit as st
import pandas as pd
# Sample DataFrame
data = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'Score': [85, 90, 78]
})
st.table(data)
Using st.dataframe()
for Interactive Tables
If you need a scrollable and interactive table, use st.dataframe()
instead:
st.dataframe(data)
This allows users to sort, filter, and scroll through large datasets.
Displaying Tables in Evidence
For structured data visualization and reporting, Evidence provides a SQL-driven approach using its <DataTable/>
component. Instead of manually loading DataFrames in Python, Evidence connects directly to a SQL database and renders tables dynamically.
Data Table from SQL Query
Display a table from data returned from a SQL query.
```sql my_query
SELECT name, age, score
FROM users
```
<DataTable data={my_query} />
This ensures that tables remain query-driven and dynamically updated, allowing users to explore real-time data without needing Python scripts.
Pick Specific Columns
Choose which columns to display in the table.
```sql my_query
SELECT name, age, score
FROM users
```
<DataTable data={my_query}>
<Column id=name />
<Column id=score />
</DataTable>
Conditional Formatting
Apply conditional formatting to a column.
<DataTable data={my_query}>
<Column id=name />
<Column id=score colorScale=default />
</DataTable>
Streamlit Tables vs. Evidence Data Tables
Feature | Streamlit Table | Evidence Data Table |
---|---|---|
Static Tables | ✔️ | ✔️ |
Interactive Tables | ✔️ | ✔️ |
SQL-Driven | ✖️ | ✔️ |
Interactive Query Updates | ✖️ | ✔️ |
For interactive data visualization and reporting, Evidence’s <DataTable/>
provides a structured, SQL-native approach that eliminates the need for scripting.
Check out more features in the Evidence documentation.