Creating Interactive Data Reports With 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. 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') 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: Documentation GitHubWebsiteDemos
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.
Datapane is a Python module that enables you to quickly create shareable reports from existing data analysis components like Pandas DataFrames and plots.
["dashboards", "Data Visualisation", "interactive plots", "Python data visualization tools", "Python Libraries", "report"]
["Go", "dashboards", "report", "Plotly", "Python Libraries", "Data Visualisation", "R", "Git", "interactive plots", "Python", "analytics", "JavaScript", "GitHub", "Python data visualization tools", "Java", "Pandas"]
["analytics", "Pandas", "Plotly", "Python", "R", "JavaScript", "Go", "Java", "Git", "GitHub"]
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.