Streamlit and Pygwalker: Simplifying Data Visualization and Exploration

Welcome to an exciting adventure into the world of data exploration using Streamlit and Pygwalker. In this journey, we will discover the amazing capabilities of these powerful tools in analyzing data and creating captivating visualizations. Get ready for an immersive experience!

Introducing Streamlit

Streamlit is a Python library that revolutionizes the process of transforming data scripts into interactive web applications. It simplifies web development and coding challenges, making it fast, open-source, and free. With Streamlit, you can effortlessly build and share data applications without the complexities of traditional web development.

Introducing Pygwalker

Pygwalker is a popular Python library designed specifically for data analysis and visualization. It provides data scientists and analysts with an intuitive interface for generating stunning visualizations, including scatter plots, line plots, bar charts, and histograms. The best part? You don’t need any coding skills to use Pygwalker!

To explore Pygwalker further and access additional examples and resources, visit the official Pygwalker GitHub Page.

Getting Started with Streamlit and Pygwalker

Let’s ensure that your computer is ready for Streamlit and Pygwalker. Make sure you have a Python environment (version 3.6 or higher) installed. Once you’ve set that up, follow these steps to get started:

Installing the Dependencies

Open your command prompt or terminal and run the following commands to install the necessary dependencies:

pip install pandas
pip install pygwalker
pip install streamlit

Integrating Pygwalker into a Streamlit Application

Now, let’s create a Streamlit application that incorporates Pygwalker. Create a new Python script called pygwalker_demo.py and add the following code:

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="Using Pygwalker with Streamlit",
    layout="wide"
)

# Add a title
st.title("Using Pygwalker with Streamlit")

# Import your 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 launch the Streamlit application and start exploring your data, open your command prompt or terminal and execute the following command:

streamlit run pygwalker_demo.py

You will see some information displayed in the terminal. Access the Streamlit app in your web browser using the provided URL:

Local URL: http://localhost:8501

Network URL: http://xxx.xxx.xxx.xxx:8501

Open the provided URL (http://localhost:8501) in your browser and witness the power of Pygwalker’s intuitive 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:

Step 1. Click the export button on the chart.

Step 2. Click the copy code button.

Step 3. Paste the copied code into your Python script where needed.

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="Using Pygwalker with Streamlit",
    layout="wide"
)

# Add a title
st.title("Using Pygwalker with Streamlit")

# Import your 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 = """<PASTE_COPIED_CODE_HERE>"""

# 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)

Remember to refresh the webpage to see the saved state of your Pygwalker chart.

It’s important to note that Pygwalker is built on top of graphic-walker, a powerful library that can be integrated into various platforms such as Excel and Airtable. This allows your Pygwalker app to collaborate seamlessly with users in different environments, leveraging the capabilities of graphic-walker and Pygwalker.

Conclusion

Streamlit and Pygwalker are invaluable tools that simplify the process of data exploration and enable effective communication of insights. Streamlit’s user-friendly interface combined with Pygwalker’s interactive visualization options enhance the data analysis workflow. So dive into your data, uncover remarkable insights, and share your discoveries with the world!

References

For more detailed information, you can refer to this documentation to learn how to use Streamlit with Pygwalker.

Leave a comment

Design a site like this with WordPress.com
Get started