DEV Community

FlyingBanana
FlyingBanana

Posted on

PyGWalker + Gradio = free Tableau

Interactive Demo on Huggingface

Interactive Data Visualization with PyGWalker & Gradio

pygwalker is a powerful tool for data scientists, akin to Tableau or PowerBI, to instantly transform data into interactive visuals within Jupyter Notebooks. But, the challenge arises in sharing these interactive experiences. Enter Gradio - a library that swiftly turns machine learning models and functions into web apps. This article provides a quick guide on pairing pygwalker with Gradio for enhanced data sharing.

Quick Introduction to Gradio

Gradio is more than just a Python library. It’s a bridge that connects your data or model with a user-friendly interface, making it simple to create and share web apps in just a few code lines.

Getting Started with PyGWalker in Gradio

Ensure you're running Python 3.6 or above. Then, you can commence with the following steps:

1. Set Up Your Environment

Ensure you've installed both pygwalker and gradio:

pip install pygwalker gradio
Enter fullscreen mode Exit fullscreen mode

2. Code Preparations

Kick things off by importing the required libraries:

import gradio as gr
import pygwalker as pyg
from datasets import load_dataset
Enter fullscreen mode Exit fullscreen mode

3. Data Loading

Here, we'll employ the NYC-Airbnb dataset from Gradio, though you're free to select your dataset:

dataset = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
df = dataset.to_pandas()
Enter fullscreen mode Exit fullscreen mode

4. Crafting the Gradio Interface

Using Gradio's Blocks feature, set up the UI components:

with gr.Blocks() as demo:
    gr.Label("Visualize NYC-Airbnb Data with PyGWalker & Gradio")
    gr.Markdown("Experience data interaction using pygwalker and gradio. Dive deep with drag-and-drop or commence your analysis!")
    gr.HTML(pyg.walk(dataset=df, spec="./viz-config.json", debug=False, return_html=True))
Enter fullscreen mode Exit fullscreen mode

This segment configures the title, description, and integrates the pygwalker visualization into the Gradio UI.

5. Go Live!

Launch your web app with:

demo.launch()
Enter fullscreen mode Exit fullscreen mode

Upon running, you'll witness the interactive visualization in a browser. Delve into the dataset using intuitive drag-and-drop or employ natural language (a kanaries API key activation is needed).

Interactive Demo on Huggingface

Wrapping Up

Merging pygwalker with gradio presents a streamlined avenue to craft and disseminate interactive data visualizations. This combo doesn't just amplify data probing but also broadens data insights' reach, granting even those without a tech background the ability to engage with your discoveries. Dive in and let the world see your insights!

Dive Deeper

Top comments (0)