MITB Banner

Creating Interactive Data Reports With Datapane

Datapane is a Python module that enables you to quickly create shareable reports from existing data analysis components like Pandas DataFrames and plots from a wide range of visualisation libraries like Plotly and Bokeh.
Share
datapane

One of the issues of using Python for data analytics is the inability to create shareable data visualization reports quickly. Other analytics tools like PowerBI and Tableau can readily publish and share reports. Sure, you can create shareable reports with modules like dash and Flask but they require quite a bit of extra code. Datapane is a Python module that enables you to quickly create shareable reports from existing data analysis components like Pandas DataFrames and plots from a wide range of visualisation libraries like Plotly and Bokeh. Check out this article to learn the basics of creating a report with Datapane. Recently Datapane has introduced new components that make creating basic reports even easier and allow analysts to exercise more control over the report layout and view.  

DataTable

One of these components is the DataTable block; this is an extremely powerful component, so much so that it facilitates the creation of a basic data report with just a few lines of code. The DataTable block takes a DataFrame and creates an interactive table that allows sort and search operations. In addition to that, it incorporates data analysis tools like Pandas-Profiling and SandDance by default.  

Let’s create a barebones report for the wine quality dataset using just the DataTable block. First, let’s install and set up Datapane.

Install from PyPI

pip install -U datapane

 To publish and share reports, you’ll need an API token. Register on the Datapane website and get your token from the account settings. 

 import datapane as dp 
 dp.login('API TOKEN') 

Load the dataset and pass the DataFrame object to dp.DataTable. Publish the DataTable block using dp.Report(block_name).publish(‘Report Name’, ‘Report Description’)

 import datapane as dp 
 import pandas as pd
 df = pd.read_csv("winequality_white.csv")
 table = dp.DataTable(df)
 dp.Report(table).publish(name='WineData', description='Winedata Example') 

That’s it! If you visit the above link you’ll find an interactive table like this. 

Not only that, using the buttons in the top-right corner, you can analyze the data with Padas-Profiling and SandDance.

Pandas Profiling report on Datapane
SandDance plots on Datapane

You can learn more about dp.DataTable here.

More Sophisticated Layouts 

The default layout of Datapane reports is good enough for basic use cases, but if you want to create an intricate report layout with multiple pages, you can do so with Select, Group and Page components.

The dp.Select component enables you to create different tabs for different blocks. Let’s say we have three components we want to display: white wine interactive table, source code of the whole report and a 3D scatter plot of pH, alcohol content and density. 

To share syntax-highlighted code instead of simple formatted text, we can use another one of the new components, dp.Code. It currently only supports Python and Javascript.

 white = pd.read_csv("winequality_white.csv")
 white_table = dp.DataTable(white)
 fig_3D = px.scatter_3d(white, x='pH', y='alcohol', z='density',
               color='quality')

 # Create plot component from the 3D scatter plot
 plot_3D = dp.Plot(fig_3D, label = '3D Scatter Plot')

 # Create the selection of tabs 
 select = dp.Select(blocks=[
     dp.DataTable(white, label ="Table"),
     dp.Code(source_code, label='Source code'),
     plot_3D
     ]) 

You can learn more about dp.Select here.

dp.Group can be used to display components side-by-side. Let’s say we want to display the interactive table for red wine data alongside a scatter plot of citric acid and quality.

 red = pd.read_csv("winequality_red.csv")
 red_table = dp.DataTable(red)
 fig = px.scatter(data_frame=white,
           x='citric acid',
           y='quality')

 # Create plot component
 plot_2D = dp.Plot(fig)

 # Group table component and plot component
 group = dp.Group(blocks=[red_table, plot_2D],
                 columns=2) 

You can learn more dp.Group here.

To facilitate the creation of multi-page reports Datapane provides the dp.Page component. Let’s create a combined report of both the wine types using the previously created Select and Group components.

 page1 =  dp.Page(label='Red Wine',
                 blocks=['## Red Wine', group]
                 )
 page2 = dp.Page(label='White Wine',
                 blocks=['## White Wine', select]
                 )
 dp.Report(page1, page2).publish(name='Wine Layout Example') 
Final multi-page datapane report

You can learn more about dp.Page here.

The above report and its source code can be found here

References:

To learn more about Datapane please refer to the following resources:

PS: The story was written using a keyboard.
Picture of Aditya Singh

Aditya Singh

A machine learning enthusiast with a knack for finding patterns. In my free time, I like to delve into the world of non-fiction books and video essays.
Related Posts

Download our Mobile App

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

3 Ways to Join our Community

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our Daily newsletter

Get our daily awesome stories & videos in your inbox
Recent Stories

Featured

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

AIM Conference Calendar

Immerse yourself in AI and business conferences tailored to your role, designed to elevate your performance and empower you to accomplish your organization’s vital objectives. Revel in intimate events that encapsulate the heart and soul of the AI Industry.

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed