PyGWalker Streamlit API Guide
This guide explains how to integrate PyGWalker with Streamlit applications, providing interactive data visualization capabilities.
StreamlitRenderer Class
The StreamlitRenderer
class is the main interface for using PyGWalker in Streamlit apps.
from pygwalker.api.streamlit import StreamlitRenderer
renderer = StreamlitRenderer(df, spec="./gw_config.json")
Key Parameters
Parameter | Type | Default | Description |
---|---|---|---|
dataset | Union[DataFrame, Connector] | - | Input data source |
spec | str | "" | Chart configuration data (ID, JSON, or URL) |
spec_io_mode | Literal["r", "rw"] | "r" | Spec I/O mode: "r" (read) or "rw" (read/write) |
kernel_computation | bool | None | Enable high-performance kernel computation |
appearance | Literal['media', 'light', 'dark'] | 'media' | Theme setting |
default_tab | Literal["data", "vis"] | "vis" | Default tab to show |
Main Methods
1. explorer()
Displays the full GraphicWalker UI.
renderer.explorer(width=None, height=1000, scrolling=False, default_tab="vis")
2. chart(index)
Renders a specific chart.
renderer.chart(index, width=None, height=1000, scrolling=False)
3. viewer()
Displays a view-only version of the charts.
renderer.viewer(width=None, height=1000, scrolling=False)
Best Practices
-
Caching: Use Streamlit's caching to prevent memory issues:
@st.cache_resource def get_pyg_renderer(): df = pd.read_csv("data.csv") return StreamlitRenderer(df, spec="./gw_config.json")
-
Large Datasets: Enable
kernel_computation=True
for better performance with large datasets. -
Layout: Use Streamlit's layout options (e.g.,
st.set_page_config(layout="wide")
) for optimal display. -
Tabs: Organize different PyGWalker views using Streamlit tabs for a cleaner interface.
Example: Streamlit App with PyGWalker
import streamlit as st
from pygwalker.api.streamlit import StreamlitRenderer
import pandas as pd
st.set_page_config(page_title="PyGWalker in Streamlit", layout="wide")
st.title("PyGWalker in Streamlit Demo")
@st.cache_resource
def get_pyg_renderer() -> StreamlitRenderer:
df = pd.read_csv("data.csv")
return StreamlitRenderer(df, spec="./gw_config.json", spec_io_mode="rw")
renderer = get_pyg_renderer()
tab1, tab2, tab3 = st.tabs(["Explorer", "Data Profiling", "Charts"])
with tab1:
renderer.explorer()
with tab2:
renderer.explorer(default_tab="data")
with tab3:
st.subheader("Registered per Weekday")
renderer.chart(0)
st.subheader("Registered per Day")
renderer.chart(1)
Advanced: Building a Tableau/PowerBI Alternative
To create an open-source alternative to Tableau/PowerBI that can handle large datasets:
- Use PyGWalker for interactive visualizations
- Leverage Streamlit for the web application framework
- Integrate with Snowflake for handling large-scale data
This combination provides a powerful, scalable solution for data visualization and analysis.
For more details and advanced usage, refer to the PyGWalker documentation (opens in a new tab).
Related Q&A
How to build a online open source alternative to Tableau/PowerBI which can handle large amount of data?
Answer: You can use pygwalker + streamlit + snowflake to build a online open source alternative to Tableau/PowerBI which can handle large amount of data.