class: center, middle, inverse, title-slide # Building sarbR ##
### Hanjo Odendaal --- class: middle, no_number, animated, fadeIn background-image: url(images/about.png) background-size: cover --- class: center, middle, transition, animated, slideInRight # Motivation --- class: center, general_slide, animated, fadeIn # Disclaimer * This package is in no way endorsed or associated with the South African Reserve Bank * Given that no formal API is provided, the maintainers of this package rely on their own infrastructure to collect, curate, clean and maintain an up to date database * Although the greatest care is taken to provide good data, the maintainer/s of this package take no responsibility in the service OR data being supplied * This package uses self-signed certificates on the API’s side --- class: center, general_slide, animated, fadeIn # About the Package .large[The goal of sarbR is to provide an easy interface to the monthly release of the South African Reserve Bank Quarterly Bulletin data. Although the SARB has many other datasets, the Quarterly Bulletin makes up the bulk of the statistical release] ??? Why did I start working on the package * Needed indicators for analysis, didnt really know where to find it * Date format is always an issue * Selfish... how to implement some kind of auth --- class: general_slide, animated, fadeIn # What the SARB provides .pull-left[ <img src="images/presentation/sarb_files.png" width="80%" /> ] .pull-right[ <img src="images/presentation/sarb_xlsx.png" width="60%" /> ] --- class: general_slide, animated, fadeIn # Output from sarbR ```r # Install development version from GitHub devtools::install_github("HanjoStudy/sarbR") library(sarbR) sarbR::sarb_code(code = "KBP1000J") ``` ``` ## # A tibble: 59 x 6 ## date original_date classification frequency code value ## <chr> <chr> <chr> <chr> <chr> <int> ## 1 1960-01-01 19600000 money_and_banking J1 KBP1000J 243 ## 2 1961-01-01 19610000 money_and_banking J1 KBP1000J 255 ## 3 1962-01-01 19620000 money_and_banking J1 KBP1000J 276 ## 4 1963-01-01 19630000 money_and_banking J1 KBP1000J 302 ## 5 1964-01-01 19640000 money_and_banking J1 KBP1000J 337 ## 6 1965-01-01 19650000 money_and_banking J1 KBP1000J 355 ## 7 1966-01-01 19660000 money_and_banking J1 KBP1000J 400 ## 8 1967-01-01 19670000 money_and_banking J1 KBP1000J 424 ## 9 1968-01-01 19680000 money_and_banking J1 KBP1000J 452 ## 10 1969-01-01 19690000 money_and_banking J1 KBP1000J 502 ## # … with 49 more rows ``` --- background-color: black background-image: url('https://media.giphy.com/media/B1TMcmoBAaSZi/giphy.gif') background-size: contain ??? Some notes --- class: center, middle, transition, animated, slideInRight # Workflow of the package --- background-color: #312f40 <iframe src="https://hanjostudy.github.io/sarbR/" width="100%" height="600px"></iframe> --- background-image: url(images/package_page.png) background-size: contain --- class: center, middle, transition, animated, slideInRight # Back-End --- class: center, middle, general_slide, animated, fadeIn <img src="images/presentation/schematic.png" width="90%" /> --- class: middle, general_slide, animated, fadeIn ```bash BUILD: docker build -t sarbapi . RUN: docker run --name sarbR -d -p 80:80 -p 443:443 \\ -v `pwd`/sarb_api_func.R:/sarb_api_func.R \\ -v `pwd`/sarb_api.R:/sarb_api.R \\ -v `pwd`/start_api.R:/start_api.R sarbapi sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT sudo iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPT ``` -- ```bash FROM rocker/r-base MAINTAINER Hanjo Odendaal <hanjo.oden@gmail.com> *# system RUN apt-get update -qq && apt-get install -y \ git-core \ libssl-dev \ libcurl4-gnutls-dev \ libmysqlclient-dev *## R libraries RUN install2.r -e plumber DBI RMySQL dplyr dbplyr RUN install2.r -e glue jsonlite digest RUN install2.r -e tidyr ENV db_user user ENV db_pass thedockeywalkstotown ENV db_name database ``` --- class: middle, general_slide, animated, fadeIn ```bash *# setup nginx RUN apt-get update && \ apt-get install -y nginx apache2-utils && \ htpasswd -bc /etc/nginx/.htpasswd username password ADD daeconomist.conf daeconomist.conf *# Generate the certificate RUN openssl req -subj '/CN=mywebsite.com' -x509 -newkey rsa:4096 -nodes \ -sha256 \ -days 3650 \ -keyout /etc/ssl/private/server.key \ -out /etc/ssl/private/server.crt ADD ./nginx.conf /etc/nginx/nginx.conf ADD ./proxy.conf /etc/nginx/proxy.conf EXPOSE 80 443 CMD service nginx start && R -e "source('start_api.R')" ``` --- class: chart_left, animated, fadeIn # Conclusion .chart_pull-left[ * Learned to implement some kind of auth alongside API * Got to grips with docker * Hopefully built something useful ] .chart_pull-right[ ![](https://media.giphy.com/media/3ohs86vZAWiJXWvQI0/giphy.gif) ]