File size: 2,190 Bytes
2db80a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# import the required libraries
import streamlit as st # for creating interactive web apps
import pandas as pd # for data manipulation and analysis
import pygwalker as pyg # for graph-based data analysis
from streamlit_option_menu import option_menu # for creating a custom option menu widget
from pygwalker.api.streamlit import StreamlitRenderer, init_streamlit_comm # for rendering and communicating with pygwalker graphs

from streamlit_extras.switch_page_button import switch_page # for creating a button to switch between pages
st.set_page_config(page_title="Data Analysis & Visualization Tool", layout="wide") # set the page title and layout of the web app
st.title("Home Page") # display the title of the web app

selected = option_menu(menu_title=None, options=["EDA & Visualize", "Dashboard"], orientation="horizontal") # create an option menu widget with two options and a horizontal orientation

def main(): # define the main function
    uploaded_data=st.file_uploader("Upload your data", type=["csv","xlsx","json"]) # create a file uploader widget to let the user upload their data

    if uploaded_data is not None: # check if the user has uploaded any data
       dataset=pd.read_csv(uploaded_data) # read the data as a pandas dataframe

    if selected=="EDA & Visualize" and uploaded_data is not None:
      # Establish communication between pygwalker and streamlit
      init_streamlit_comm()
      # Get an instance of pygwalker's renderer. You should cache this instance to effectively prevent the growth of in-process memory.
      @st.cache_resource
      def get_pyg_renderer(dataset) -> "StreamlitRenderer":
         df = dataset.copy()
         # When you need to publish your app to the public, you should set the debug parameter to False to prevent other users from writing to your chart configuration file.
         return StreamlitRenderer(df, spec="./gw_config.json", debug=False)
      renderer = get_pyg_renderer(dataset)
      # Render your data exploration interface. Developers can use it to build charts by drag and drop.
      renderer.render_explore()
    elif selected=="Dashboard":
       switch_page("Dashboard")

if __name__=="__main__":
   main()