Triangular Tables |> Table Contest

Triangular Tables

Authors: Michael Moskowitz
Github

Abstract: Most tabular data takes the shape of a rectangle, with each row having a value for each column. But sometimes that's not the case. Claim payment data used by insurance companies is an example of data that takes a triangular shape. This tutorial explains how to use some non-standard techniques to nicely format and interact with these kinds of tables.

Full Description: In some types of insurance, claims can stay open for many years. For example, an insurance company may still be making payments today for a claim that occurred in 2015.

It is common to examine the total amount of claim payments that have been made for a given year at 12 month increments. If you imagine a table where the first column is the year, and each subsequent column shows the total claim payments that have been made for that year at 12 month increments, then naturally rows for older years will have more columns filled in and rows for more recent years will have fewer columns filled in. The data naturally takes the shape of a triangle.

With this type of data, half of the cells will always be empty. This can make it difficult to format the table in a way that looks good. Table packages vary in how specific you can be with targeting which rows/columns/cells to format, and none of them have any built in functionality that I'm aware of that can format the table in the way that is needed here. That is what I attempt to do in this table.

Additionally, it is often useful to apply conditional formatting to a table to help analyze it. Conditional formatting is not necessarily difficult to apply, but many examples assume the table is static and apply the formatting to the table structure itself. In a scenario where many datasets need to be analyzed, the ability to swap out the data in the table is necessary. This means that the formatting needs to be part of the data itself, which I demonstrate how to do.

Making the table interactive can also be useful. It might be useful to select a cell and see details about that value. But since not all the cells in the table have values or are meant to be clicked, that needs to be controlled for as well. The DT package does have some functionality to control this, but not in the exact way that is needed here. In this table I show how this is possible to accomplish.

Although the DT package has many formatting features, it doesn't have built in helper functions in R to accomplish what is needed here. But luckily it does provide a way to pass in callbacks that can be used by the DataTables javascript library. Since the callbacks need to be written in javascript, this makes this somewhat of an intermediate/advanced feature. In my app I include a tutorial that goes through all the steps and code needed to create these non-standard tables.


Table Type: interactive-Shiny
Submission Type: Tutorial
Table: Trianglular Tables
Code: GitHub - Mosk915/RStudioTableContest2022
Cloud project:
Languages: Built with R: true. Built with Python: false.
Industries: Insurance.
Other packages: DT, shiny

1 Like