Top 5 Python Libraries to Host and Share Your PyGWalker as a Web App
In today's fast-paced data-centric world, sharing your insights is just as important as deriving them. Python, being a leading language in data science, offers numerous libraries to create web apps out of your data analyses. If you're a fan of pygwalker
for interactive visualization, you're in luck! This blog post will uncover the top 5 libraries to host and share your pygwalker
visualizations as web apps.
- Streamlit
- Gradio
- Dash
- Shiny-Python
- Flask
1. Streamlit
Overview:
Streamlit (opens in a new tab) is an immensely popular Python library that transforms data scripts into shareable web apps within minutes instead of weeks. You can think of Streamlit as Flask tailored for data scientists, enabling rapid data app development without needing to dive into web development intricacies. What's more, Streamlit provides a seamless platform to convert pygwalker
into a live web application, letting you share with a broader audience and not just present static reports. The user can pose questions and continue exploration based on their requirements.
Key Features:
- Simplicity: Transform your data scripts into web apps with just a few lines of code.
- Interactive Widgets: Easily add sliders, buttons, and text inputs to manipulate visualizations.
- Hot-reloading: See changes in real-time without restarting your app.
Integrating with PyGWalker:
Streamlit and PyGWalker offer a potent combination. The recent API in pygwalker
facilitates its use with Streamlit, enabling the duckdb
computation engine, a feature exclusive to their combination. Here's a step-by-step integration guide:
-
Setting up the environment: Make sure you have Python 3.6 or higher. Install the necessary dependencies using:
pip install pandas pygwalker streamlit
-
Embedding PyGWalker into Streamlit: Create a new Python script named
pygwalker_demo.py
. Utilize theStreamlitRenderer
frompygwalker.api.streamlit
for a seamless integration:from pygwalker.api.streamlit import StreamlitRenderer, init_streamlit_comm import pandas as pd import streamlit as st st.set_page_config( page_title="Use Pygwalker In Streamlit", layout="wide" ) init_streamlit_comm() st.title("Use Pygwalker In Streamlit") @st.cache_resource def get_pyg_renderer() -> "StreamlitRenderer": df = pd.read_csv("https://kanaries-app.s3.ap-northeast-1.amazonaws.com/public-datasets/bike_sharing_dc.csv") return StreamlitRenderer(df, spec="./gw_config.json", debug=False) renderer = get_pyg_renderer() renderer.render_explore()
-
Exploring Data in Streamlit using PyGWalker: Execute your Streamlit app using the command:
streamlit run pygwalker_demo.py
. This command will start your Streamlit app, and you can interactively visualize your data using PyGWalker's intuitive drag-and-drop functionality. -
Saving PyGWalker Chart State: When your pygwalker renderer is in debug mode and the
spec
parameter points to a local JSON file path, you can save your chart configuration by hitting the save button on the exploration interface.
Further reading: How to Use PyGWalker with Streamlit
2. Gradio
Overview: Gradio (opens in a new tab) empowers you to build a UI around machine learning models. But, it's not limited to just that. Its ease of building custom interfaces is unparalleled.
Key Features:
- Interface Flexibility: Craft interfaces from dropdowns, sliders, textboxes, and more.
- Rapid Deployment: Build and deploy ML prototypes quickly.
- Sharing: Obtain shareable links for your apps, enabling easy collaboration.
Integrating with PyGWalker:
Gradio's HTML
interface component can host pygwalker
visualizations.
import gradio as gr
import pygwalker as pyg
html_code = pyg.walk(..., return_html=True)
gr.Interface(fn=None, inputs=None, outputs=gr.HTML()).launch()
Further reading: How to Use PyGWalker with Gradio
3. Dash
Overview: Dash (opens in a new tab) by Plotly is a productive framework for building analytical web applications. No JavaScript required.
Key Features:
- Reactive: Build reactive apps around Plotly charts.
- Customizable: Craft your UI with a vast range of Dash components.
- Integration: Extends support for other Plotly charting libraries.
Integrating with PyGWalker:
With Dash's html.Div
component, pygwalker
visualizations can be smoothly incorporated.
import dash
import dash_dangerously_set_inner_html
import dash_html_components as html
import pygwalker as pyg
from datasets import load_dataset
# load dataset
dataset = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
df = dataset.to_pandas()
app = dash.Dash()
html_code = pyg.walk(df, return_html=True)
app.layout = html.Div([
dash_dangerously_set_inner_html.DangerouslySetInnerHTML(html_code),
])
if __name__ == '__main__':
app.run_server(debug=True)
4. Shiny-Python
Overview:
While R's Shiny library is renowned for interactive apps, the Python port, shiny
, brings similar capabilities to Python.
Key Features:
- Reactivity: Build apps with reactive bindings for live updates.
- UI Components: Shiny offers a plethora of UI components.
Integrating with PyGWalker:
Using the ui.HTML
component, pygwalker
visualizations can be embedded within the Shiny app.
from shiny import App, ui
import pygwalker as pyg
html_code = pyg.walk(..., return_html=True)
app_ui = ui.page_fluid(
ui.HTML(html_code)
)
app = App(app_ui)
Further reading: How to Use PyGWalker with Shiny-Python
5. Flask
Overview: Flask (opens in a new tab) is a lightweight WSGI web application framework. While not specifically for data apps, its flexibility is unbeatable.
Key Features:
- Microframework: Flask gives you the basics to run a web app.
- Extensions: Enhance Flask's capabilities through extensions.
Integrating with PyGWalker:
You can render the pygwalker
HTML within a Flask app using the render_template
function.
from flask import Flask, render_template_string
import pygwalker as pyg
app = Flask(__name__)
@app.route('/')
def home():
html_code = pyg.walk(..., return_html=True)
return render_template_string(html_code)
if __name__ == '__main__':
app.run(debug=True)
Conclusion
Your data stories deserve a wider audience, and these libraries make it happen! Whether you're building a simple prototype or a full-fledged data app, these libraries coupled with pygwalker
provide a powerful combo to make your data accessible and interactive. Dive in, experiment, and let your visualizations shine on the web!