Discover great_tables: The Python Answer to R's {gt} Package for Table Formatting in Quarto and Shiny for Python

Reading time:
time
min
By:
Gift Kenneth
March 28, 2024

Crafting compelling narratives often depends on presenting insights clearly and effectively. This skill is key for data science. For users of R's {gt} package, it has provided a powerful and flexible way to create publication-quality tables in Quarto reports or Shiny apps such as clinical trial reports, research documents, and business analytics reports.

However, Python users are searching for a similar tool. This search has led to the rise of great_tables —a promising library designed to bridge this gap and enhance table formatting in Quarto and Shiny for Python. 

Discover how to craft professional-grade clinical tables in R. Follow our guide to get started with {gt} package.

In this blog post, you'll explore the capabilities of great_tables and see how it helps Python users improve their data presentations.

Why great_tables?

Data Scientists can toggle between R and Python, leveraging each language's strengths in their data analysis workflows. The challenge has been the absence of a gt equivalent in Python, especially noted in Shiny applications where well-formatted tables are essential. 

Table formatting with great_tables starts with your data typically in a Pandas or Polars DataFrame after which you can design your table by selecting the specific elements and styling options that best fit your project’s requirements. 

The Parts of a gt Table

great_tables mirrors the {gt} package's ability to accurately format tables, making it a go-to for Python enthusiasts seeking to enhance their data presentations. It’s not a coincidence as they both come from Posit!

Whether you're preparing a Quarto report or developing a Shiny for Python application, great_tables ensures your tables are informative and visually appealing. You can render your table directly in the console, embed it in a Jupyter notebook. 

Key benefits of great_tables:

  • Provides a familiar experience for gt users transitioning to Python.
  • Enables intricate table customization and styling.
  • Integrates seamlessly with Quarto and Shiny for Python and potentially with Streamlit.
  • Easy-to-use syntax mirroring gt.
  • Extensive customization for table appearance.
  • Seamless integration with Python data science tools.
Explore innovative ways to supercharge your Shiny for Python apps – learn how to leverage custom components in this comprehensive guide

Getting Started with great_tables

Let’s build an application that displays stock market data (specifically, the S&P 500 index) in a table format. 

Importing Libraries and Setting Up Data

Determining Date Range for the Data

This will compute the minimum and maximum dates available in the sp500 dataset and then set a default date range (START_DATE to END_DATE) for the table display.

Creating the User Interface

Defining Helper Functions for Date Handling

Convert a date object into a string in YYYY-MM-DD format, which is necessary for filtering the dataset.

Setting Up Server Logic

Reactive Data Filtering Based on User Input

Include functions to update the data displayed in the table based on the date range the user selects.

Rendering the Table

Finally, use great_tables to format and display the S&P 500 data in a table within the web application.

Here’s the entire code:

Make informed decisions for your data projects! Explore the strengths of Streamlit and Shiny for your next dashboard.

Summing Up Python’s great_tables

For data scientists and analysts who rely on Python and have experience with R's gt package, great_tables offers a familiar and powerful toolset for creating detailed and customized tables. Its integration with Quarto and Shiny for Python ensures a seamless transition and consistent experience across both languages.

Explore great_tables and enhance your data presentations in Python with the finesse and precision that gt users have long enjoyed in R.=

Ready to innovate in clinical research? Explore how Shiny and Quarto are reshaping interactive reports.
Explore Possibilities

Share Your Data Goals with Us

From advanced analytics to platform development and pharma consulting, we craft solutions tailored to your needs.