Unleashing the Power of Streamlit with PyGWalker
Immerse yourself in the world of data exploration with two powerful tools: Streamlit and Pygwalker. These incredible Python libraries make analyzing and visualizing data a breeze, even if you’re new to coding. Let’s take a closer look at what makes Streamlit and Pygwalker such valuable assets in your data analysis toolkit. ## Streamlit: Effortlessly Transforming Data Scripts into Web Apps If you’re tired of grappling with the complexities of web development and coding, Streamlit is the answer to your prayers. This speedy and open-source library allows you to effortlessly transform your data scripts into interactive web applications. With Streamlit, you’ll save time and effort, enabling you to focus on exploring and presenting your data rather than getting lost in code. ## Pygwalker: Easy Data Visualization and Analysis Enter Pygwalker, a popular Python library designed for data analysis and visualization. Even if you’re not a coding whiz, Pygwalker provides an intuitive interface for generating captivating visualizations that will wow your audience. Scatter plots, line plots, histograms, and bar charts are just a few examples of the stunning visualizations you can create. Leave the coding to Pygwalker and unleash your creativity. ## Getting Started with Streamlit and Pygwalker Before diving into the world of data exploration, let’s ensure you have the necessary setup on your computer. Make sure you have a Python anaconda solving environment too long with version 3.6 or higher. Once that’s sorted, follow these steps to get started: ### Installing the Dependencies Fire up your command prompt or terminal and install the required dependencies with these commands: «`shell pip install pandas pip install pygwalker pip install streamlit «` ### Integrating Pygwalker into a Streamlit Application Now that all the dependencies are in place, let’s create a Streamlit application that incorporates Pygwalker. Create a new Python script called `pygwalker_demo.py` and add the following code: «`python import pygwalker as pyg import pandas as pd import streamlit.components.v1 as components import streamlit as st # Configure the Streamlit page st.set_page_config( page_title=»Exploring Data with Pygwalker and Streamlit», layout=»wide» ) # Display a title st.title(«Using Pygwalker with Streamlit») # Import the data df = pd.read_csv(«https://sample.csv»😉 # Generate the HTML using Pygwalker pyg_html = pyg.walk(df, return_html=True) # Embed the generated HTML into the Streamlit app components.html(pyg_html, height=1000, scrolling=True) «` ### Exploring Data with Pygwalker in Streamlit To embark on your data exploration journey, run the following command in your command prompt or terminal: «`shell streamlit run pygwalker_demo.py «` You’ll see some information displayed on the terminal. Access the Streamlit app in your browser using the provided URL: Local URL: [http://localhost:8501](http://localhost:8501) Network URL: [http://xxx.xxx.xxx.xxx:8501](http://xxx.xxx.xxx.xxx:8501) Open the URL ([http://localhost:8501](http://localhost:8501)) in your web browser and experience Pygwalker’s powerful drag-and-drop actions for interactive data exploration and visualization. ### Saving the State of a Pygwalker Chart If you want to save the state of a Pygwalker chart, follow these simple steps: 1. Click the export button on the chart. 2. Click the copy code button. 3. Paste the copied code into your Python script where needed. «`python import pygwalker as pyg import pandas as pd import streamlit.components.v1 as components import streamlit as st # Configure the Streamlit page st.set_page_config( page_title=»Exploring Data with Pygwalker and Streamlit», layout=»wide» ) # Display a title st.title(«Using Pygwalker with Streamlit») # Import the data df = pd.read_csv(«https://kanaries-app.s3.ap-northeast-1.amazonaws.com/public-datasets/bike_sharing_dc.csv»😉 # Paste the copied Pygwalker chart code here vis_spec = «»»»»» # Generate the HTML using Pygwalker pyg_html = pyg.walk(df, spec=vis_spec, return_html=True) # Embed the generated HTML into the Streamlit app components.html(pyg_html, height=1000, scrolling=True) «` Don’t forget to refresh the webpage to see the saved state of your Pygwalker chart. It’s important to note that Pygwalker is built upon graphic-walker, making it compatible with various platforms like Excel and Airtable. This means you can collaborate with users in different environments, leveraging the power of Pygwalker and graphic-walker. ## Conclusion Say goodbye to the complexities of web development and coding challenges. Streamlit and Pygwalker are here to simplify your data exploration process and provide you with the tools to present your insights effectively. Streamlit’s user-friendly interface and Pygwalker’s interactive visualizations combine seamlessly, enhancing your data analysis workflow. Dive into your data, uncover remarkable insights, and share them with the world using Streamlit and Pygwalker. ## References — [Pygwalker GitHub Repository](https://github.com/Kanaries/pygwalker) — [Pygwalker in Streamlit Demo](https://github.com/Kanaries/pygwalker-in-streamlit) For more in-depth information, refer to the documentation on how to use [Streamlit](https://docs.kanaries.net/pygwalker/use-pygwalker-with-streamlit.en) with Pygwalker.