When I made the Hrafnagud project I recently talked about at ShinyConf (and am about to talk about at useR! in July and EARL in September), I also made several apps for myself to consume each API. The app and API for tracking my finances is called Ebenezer, named after the miserly Scrooge. My goal was to take each kind of financial instrument and make a table that fits well for it. Bonds work differently than Equity stocks, for example, and therefore, should be represented differently. The result was the following tables, which are now a part and parcel of my application.
Key Features
One of the key features of these tables are the way the colors are assigned automatically. This is done using a get_css_class() function which basically assigns the different colors and highlights wherever required.
Another important bit is how the tables themselves are constructed. Processing functions are written in the cell parameter of the reactable() call. The function then takes up a concatenated string and builds up a div structure that is styled with a custom scss file.
Setup
Here we setup some libraries, functions and load the dataframes for these examples.
Now that the data is loaded, we can take each table at a time.
Ticker
The ticker is a simple table that needs a few key pieces of information. The most important out of which is the correct semantic colour for rise and fall of a stock.
Note: While I usually consume this data from a custom API, for the sake of illustration and reproducibility, I have included a static file here as a .csv.
Alright, now that we have data for the ticker, we can create a stocks table. The table below gives you the portfolio with different fields such as Invested Value, Quantity, Average Price on the left, and Unrealized P&L, Realized P&L, Current Price on the right. If a user hovers on the icons, they will find these labels as well.
Between Stocks and Bonds, something changes. Most stock data is current. You need the most crucial information immediately. With bonds, the information needed is a bit different. You need to know the current amount, the amount it will total to when the time period passes and the progress. So, with the help of reactablefmtr, I added a progress bar to the tables.
Another thing to note is that the progress bar color changes according to a palette. This gives the user visual feedback for how far their bonds have progressed to maturity. Darker is “matures soon”.
Funds work similar to the bonds with slight variation. In some ways, they are a mixture between Stocks and Bonds. But with all the tables covered above, this one requires no explanation. This is how we can reuse most of our CSS here as well.
The key here is a column called is_sip_ongoing, which is used to split the tables into two, with slightly different structures.
SIPs
For SIPs, we have a simple reminder for each row which tells the date for the installment and the amount.