Pygwalker have supported some features that existed on jupyter:
- save chart config
- use duckdb as compute engine(support bigger datas)
But, since streamlit is a long-running service that may be exposed to the public Internet, I hope everyone can refer the best practices of pygwalker in streamlit.
import pandas as pd import streamlit.components.v1 as components import streamlit as st from pygwalker.api.streamlit import init_streamlit_comm, get_streamlit_html st.set_page_config( page_title="Use Pygwalker In Streamlit", layout="wide" ) st.title("Use Pygwalker In Streamlit(support communication)") # Initialize pygwalker communication init_streamlit_comm() # When using `use_kernel_calc=True`, you should cache your pygwalker html, if you don't want your memory to explode @st.cache_resource def get_pyg_html(df: pd.DataFrame) -> str: # When you need to publish your application, you need set `debug=False`,prevent other users to write your config file. # If you want to use feature of saving chart config, set `debug=True` html = get_streamlit_html(df, spec="./gw0.json", use_kernel_calc=True, debug=False) return html @st.cache_data def get_df() -> pd.DataFrame: return pd.read_csv("https://kanaries-app.s3.ap-northeast-1.amazonaws.com/public-datasets/bike_sharing_dc.csv") df = get_df() components.html(get_pyg_html(df), width=1300, height=1000, scrolling=True)
finally, Please read the comments in the demo code carefully before using new pygwalker in streamlit.
Pygwalker support use database as datasource(currently in experimental stage).
You can use snowflake as your datasource and compute engine.
from pygwalker.data_parsers.database_parser import Connector conn = Connector( "snowflake://user_name:password@account_identifier/database/schema", "SELECT * FROM bike_share" ) walker = pyg.walk(conn)
In the current version, we don’t recommend publishing pygwalker using
Connector to the public network.