forked from longxiaofei/pygwalker-in-streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pygwalker_comm_demo.py
29 lines (22 loc) · 1.01 KB
/
pygwalker_comm_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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.
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)