-
Notifications
You must be signed in to change notification settings - Fork 30
/
billionaires_statistics.py
76 lines (56 loc) · 1.96 KB
/
billionaires_statistics.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from typing import List
import pandas as pd
import streamlit as st
from pygwalker.api.streamlit import init_streamlit_comm, StreamlitRenderer, PreFilter
st.set_page_config(
page_title="Use Pygwalker In Streamlit",
layout="wide"
)
st.title("Billionaires Statistics")
st.subheader("data source: https://www.kaggle.com/datasets/nelgiriyewithana/billionaires-statistics-dataset/data")
# Initialize pygwalker communication
init_streamlit_comm()
@st.cache_data
def get_data() -> pd.DataFrame:
return pd.read_csv("./Billionaires Statistics Dataset.csv")
@st.cache_data
def get_all_country() -> List[str]:
return get_data()["country"].unique().tolist()
# You should cache your pygwalker renderer, if you don't want your memory to explode
@st.cache_resource
def get_pyg_renderer() -> "StreamlitRenderer":
df = get_data()
# When you need to publish your application, you need set `debug=False`,prevent other users to write your config file.
return StreamlitRenderer(df, spec="./billion_config.json", debug=False)
renderer = get_pyg_renderer()
# display explore ui, Developers can use this to prepare the charts you need to display.
# renderer.render_explore()
pre_filters = []
selected_country = st.multiselect(
'please select country',
get_all_country(),
[]
)
if selected_country:
pre_filters.append(PreFilter(
field="country",
op="one of",
value=selected_country
))
renderer.set_global_pre_filters(pre_filters)
tab1, tab2 = st.tabs(
["Area Distribution", "Gender Distribution"]
)
# display chart ui
with tab1:
st.subheader("Country Distribution")
renderer.render_pure_chart(0)
st.subheader("Area Distribution")
renderer.render_pure_chart(2)
with tab2:
st.subheader("Gender Distribution")
renderer.render_pure_chart(1)
st.subheader("Gender Distribution By Rank")
renderer.render_pure_chart(3)
st.subheader("Gender Distribution By Age")
renderer.render_pure_chart(4, width=400)