PyGWalker + Gradio = free Tableau
Tags: python, datascience, tutorial, opensource
Published: 2023-10-23 00:01:42

[![Interactive Demo on Huggingface](https://imagedelivery.net/tSvh1MGEu9IgUanmf58srQ/b725bf29-1cc8-4da0-3f65-db3207bde900/public)](https://huggingface.co/spaces/observedobserver/pygwalker-gradio)
# 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](https://gradio.app/) 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`:
```bash
pip install pygwalker gradio
```

### 2. Code Preparations
Kick things off by importing the required libraries:
```py
import gradio as gr
import pygwalker as pyg
from datasets import load_dataset
```

### 3. Data Loading
Here, we'll employ the NYC-Airbnb dataset from Gradio, though you're free to select your dataset:
```py
dataset = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
df = dataset.to_pandas()
```

### 4. Crafting the Gradio Interface
Using Gradio's `Blocks` feature, set up the UI components:
```py
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))
```
This segment configures the title, description, and integrates the `pygwalker` visualization into the Gradio UI.

### 5. Go Live!
Launch your web app with:
```py
demo.launch()
```
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](https://imagedelivery.net/tSvh1MGEu9IgUanmf58srQ/b725bf29-1cc8-4da0-3f65-db3207bde900/public)](https://huggingface.co/spaces/observedobserver/pygwalker-gradio)

## 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
- [Official PyGWalker Documentation](https://docs.kanaries.net/pygwalker)
- [Interactive Playground: pygwalker + gradio](https://huggingface.co/spaces/observedobserver/pygwalker-gradio)
- [pygwalker GitHub Repository](https://github.com/Kanaries/pygwalker)
- [Gradio Usage with pygwalker](https://docs.kanaries.net/pygwalker/tutorials/use-pygwalker-in-gradio)