Create a BIS data dashboard using rmarkdown and flexdashboard
Sometimes I need to get a quick overview of a large amount of data for a specific economy, and the task of extracting the relevant information separately from different data sets can be tedious. This is particularly true in cases where I have custom charts I want to replicate for a new economy, which for me tends to happen especially with data from the Bank for International Settlements (BIS). So when I recently came across the BIS package for R, which provides an R interface to access BIS data, I thought what better time than to automate some of this using R markdown and flexdashboard.
The code uses the BIS R package to download raw data from the BIS, which is then subsetted and reshaped for a user-specified country and fed to a function to generate the interactive plotly objects which populate the R markdown-based flexdashboard. To follow this through, see the installation instructions below.
Download source code:
How to use the code
Source the file
refresh_bis_data.Rto download raw data from the BIS and save it in a local
.RDatafile. This file will function as a local cache to avoid unnecessary calls to the BIS's servers. You will need to run this command again every time you wish to update for the latest data.
Once you have the data, call rmarkdown's
render()function to create a dashboard for an economy of your choice, identified by ISO 2-character code, e.g. “JP” for Japan.
rmarkdown::render("bis_dashboard.Rmd", params = list(ctr = "JP"), output_file = "bis_dashboard_JP.html")
When this is complete, open the HTML file produced by rmarkdown (
bis_dashboard_JP.htmlin the above example). Note that the file may take a moment to load, depending on the amount of data to display.
Examples: Dashboards for the
The dashboard will give you a set of charts for a user-specified economy as well as the global economy. The presentation is fairly self-explanatory, but sticks to the BIS's abbreviation format for concepts and identifiers in order to work well on small screens. By default, exchange rate data are based on nominal effective exchange rates (which cover fewer countries but longer history), bank liabilities are shown with a negative sign, and domestic debt securities are calculated as the difference between total and international debt securities (as some economies do not report them separately). However, the code is easily adapted for other use cases.
This dashboard is not officially related to, or endorsed by, the BIS. The code comes with no warranty.