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
Now source the file
refresh_bis_data.Rto create a local cache of the raw data and store it in a local
.RDatafile (to avoid unnecessary calls to the BIS's servers). Note that this will take a while, depending on the quality of your connection. You will need to run this the first time you generate the dashboard and every time you wish to update for the latest data.
Once you have the data, call the
renderfunction to put together 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) in your favourite browser. Note that the file may take a moment to load, depending on the amount of data to display (typically more for larger economies).
Examples: Dashboards for the
The dashboard will give you a set of charts for a specific economy and the global economy (see tabs in the top left corner). I tried to keep the presentation fairly general and self-explanatory, but chose to stick with the BIS's abbreviation format for concepts and identifiers (“XM” is the euro area, “DDS” are domestic debt securities and so on) as I wanted the dashboard to work reasonably well on small screens. For my own use case I needed nominal effective exchange rates (which cover fewer countries but longer history), bank liabilities data with a negative sign, and domestic debt securities calculated as the difference between total and international debt securities (as some countries do not report them separately), so this is what I went with, but the code is easily adapted for other scenarios.
This dashboard is not officially related to, or endorsed by, the BIS. The code comes with no warranty.