Streamlit and Pygwalker: Simplifying Data Visualization and Exploration

Experience the remarkable power of Streamlit and Pygwalker as we delve into the world of effortless data visualization and exploration. Prepare yourself for an immersive journey into the realm of interactive data analysis!

Introducing Streamlit

Say goodbye to the complexities of web development and coding challenges with Streamlit! This Python library simplifies the process of transforming your data scripts into dynamic web applications. It’s fast, open-source, and completely free—making it the perfect solution for building and sharing your data applications.

What is Pygwalker?

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

For more information about Pygwalker and access to additional examples and resources, visit the official Pygwalker GitHub Page.

Getting Started with Streamlit and Pygwalker

Before embarking on your data exploration journey, ensure that you have a Python environment installed on your computer (version 3.6 or higher). Once you have that set up, follow these simple steps:

Installation of Dependencies

To begin, open your command prompt or terminal and execute the following commands to install the necessary dependencies:

pip install pandas
pip install pygwalker
pip install streamlit

Incorporating Pygwalker into a Streamlit Application

With all the dependencies installed, 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, execute the following command in your command prompt or terminal:

streamlit run pygwalker_demo.py

You will see some information displayed on the terminal. Access the Streamlit app in your 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 web 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 wish to save the state of a Pygwalker chart, simply follow these easy steps:

  1. Click the export button on the chart.
  2. Click the copy code button.
  3. Paste the copied code into your Python script as 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 upon graphic-walker, a powerful library that can be embedded in various platforms, including Excel and Airtable. This means your Pygwalker app can easily collaborate with users in different environments, leveraging the capabilities of graphic-walker and Pygwalker.

Conclusion

With Streamlit and Pygwalker, data exploration and visualization become effortless tasks, opening up new possibilities for effective communication and insightful analysis. Streamlit’s user-friendly interface and Pygwalker’s interactive visualization options seamlessly enhance your data analysis workflow. So dive into your data with confidence and share your remarkable insights with the world!

References

For more detailed information, refer to the documentation on how to use Streamlit with PyGWalker.


Leave a comment

Design a site like this with WordPress.com
Get started