Skip to content

ObservedObserver/pygwalker-dash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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 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:

    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:

    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:

    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:

    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.

    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.

About

run pygwalker in plotly dash

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages