Streamlit Easy Data Visualisation by Using PyGWalker

Streamlit Easy Data Visualisation by Using PyGWalker


Get ready to embark on a thrilling adventure into the world of data exploration with Streamlit and Pygwalker! Discover the incredible capabilities of these two powerful Python libraries as we delve into interactive data visualization and analysis.


Introducing Streamlit


Streamlit is a game-changing Python library that takes the hassle out of building interactive web applications from your data scripts. Say goodbye to the complexities of web development and coding challenges! Streamlit is fast, open-source, and free, making it the perfect solution for creating and sharing data applications.


What Can Pygwalker Do?


Pygwalker is another fantastic Python library designed specifically for data analysis and visualization. With Pygwalker, data scientists and analysts can effortlessly generate captivating visualizations such as scatter plots, line plots, bar charts, and histograms. The best part is, you don't need any coding skills to use Pygwalker!




Use PyGWalker with Streamlit


Looking to learn more about Pygwalker and access additional examples and resources? Head over to the official [Pygwalker GitHub Page](https://github.com/Kanaries/pygwalker).


Getting Started with Streamlit and Pygwalker


Before we dive into our data exploration journey, let's ensure that your computer is equipped with a Python environment (version 3.6 or higher). Once you have that set up, follow these steps:


Step 1: Installing Dependencies


To get started, 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


Step 2: Incorporating Pygwalker in a Streamlit Application


Now that we have 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)


Step 3: Exploring Data with Pygwalker in Streamlit


To launch the Streamlit application and start exploring your data, open your command prompt or terminal and run the following command:


streamlit run pygwalker_demo.py


You will see some information displayed on the terminal. Access the Streamlit app in your web browser by visiting 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 provided URL ([http://localhost:8501](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, 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.


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 worth mentioning that Pygwalker is built upon [graphic-walker](https://github.com/Kanaries/graphic-walker), a powerful library that can be embedded in various platforms, including Excel and Airtable. This means that your Pygwalker app can easily collaborate with users in different environments, leveraging the capabilities of graphic-walker and Pygwalker.


Conclusion


Streamlit and Pygwalker are unbeatable combinations that simplify data exploration and enable effective communication of insights. Streamlit's user-friendly interface, coupled with Pygwalker's interactive visualization options, enhance your data analysis workflow seamlessly. So go ahead, dive into your data, and share your remarkable insights with the world!


References


Pygwalker GitHub Repository

Pygwalker in Streamlit Demo

How to Use Streamlit and PyGWalker 

Comments

Popular posts from this blog

How to Make a Timeline in Tableau | Step-by-Step Guide

ChatGPT Code Interpreter: Unleashing the Magic