https://github.com/observedobserver/pygwalker-dash
run pygwalker in plotly dash
https://github.com/observedobserver/pygwalker-dash
Last synced: 10 months ago
JSON representation
run pygwalker in plotly dash
- Host: GitHub
- URL: https://github.com/observedobserver/pygwalker-dash
- Owner: ObservedObserver
- License: mit
- Created: 2023-10-24T02:55:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-24T03:19:52.000Z (over 2 years ago)
- Last Synced: 2025-02-13T20:14:28.829Z (12 months ago)
- Language: Python
- Size: 5.86 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Integrating PyGWalker with Plotly Dash: A Guide
Data visualization has always been a cornerstone of data analysis. Interactive data applications elevate the user experience, enabling viewers to dive deeper into the insights. Two such powerful tools in the Python ecosystem are `PyGWalker` and `Plotly Dash`. While both serve unique purposes, when combined, they offer an enhanced data exploration environment. In this article, we will discuss integrating `PyGWalker` with `Plotly Dash`.
## An Introduction
### PyGWalker
[PyGWalker](https://github.com/Kanaries/pygwalker) is a library designed to transform your dataset into an interactive data visualization application. It simplifies data exploration, allowing users to intuitively interact with data visualizations without writing any code. Using drag-and-drop features, one can easily generate scatter plots, line charts, bar charts, and histograms.
### Plotly Dash
[Dash by Plotly](https://plotly.com/dash/) is a Python framework for building analytical web applications. With Dash, data scientists and analysts can create interactive web-based data visualizations without any knowledge of HTML, CSS, or JS. It empowers developers to build rich web applications leveraging the full capability of Plotly charts.
## Integrating PyGWalker with Dash
While Dash provides its set of visual components, integrating `PyGWalker` can provide a more fluid drag-and-drop experience, especially for those accustomed to the `PyGWalker` ecosystem. The provided code outlines a straightforward approach to achieve this integration:
### Step-by-step Guide:
1. **Setup Environment**:
If you haven't already, you will need to install the necessary libraries. This can be done using pip:
```bash
pip install dash pygwalker dash-dangerously-set-inner-html datasets
```
2. **Load Dataset**:
For this demonstration, we're using the NYC-Airbnb-Open-Data dataset from `gradio`. After loading, the dataset is converted to a Pandas DataFrame:
```python
dataset = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
df = dataset.to_pandas()
```
3. **Generate PyGWalker HTML**:
With the `walk` function from `PyGWalker`, the dataset is transformed into an interactive visualization tool. This function returns the HTML representation of the tool:
```python
html_code = pyg.walk(df, return_html=True)
```
4. **Integrate with Dash**:
By utilizing `dash-dangerously-set-inner-html`, we can insert raw HTML into our Dash app layout. While this method is powerful, as the name suggests, use it with caution. Ensure the HTML content is safe and free from malicious scripts:
```python
app.layout = html.Div([
dash_dangerously_set_inner_html.DangerouslySetInnerHTML(html_code),
])
```
5. **Run the Dash App**:
Finally, run the Dash application. If executed correctly, the browser should open a local server displaying the `PyGWalker` interface within the Dash application.
```python
if __name__ == '__main__':
app.run_server(debug=True)
```
## Conclusion
Integrating `PyGWalker` with `Plotly Dash` opens up new avenues for creating and sharing interactive data visualizations. While `Dash` offers a rich set of components for data visualization, `PyGWalker` provides an intuitive drag-and-drop interface, enhancing the user's data exploration journey.
As always, while tools like `dash-dangerously-set-inner-html` offer flexibility, they come with their set of risks. Ensure any inserted HTML is trustworthy.
Embrace this integration to provide users with a richer, more interactive data exploration environment.