example automated dashboard
library(shiny)
library(tidyverse)
devtools::load_all()
# R mixed with JS
cur_date <- Sys.time();attr(cur_date,"tzone") <- "UTC"
tags$script(shiny::HTML(glue::glue('
$(function(){{
$("#date-diff").html("Last Updated " + get_time_diff("{cur_date}") + " ago");
}});
')))
macro_data <- macro_indicators %>%
dplyr::mutate(data = purrr::map(id,~tidyquant::tq_get(.,get = "economic.data",from = Sys.Date() - 20*365)))
usethis::use_data(macro_data,overwrite = TRUE)
Macro Indicators
DISCLAIMER: Regression lines are provided for informational purposes only, fit against their 20 yr trends.
Rates
macro_data %>% chart_indicators("Interest Rates")
Inflation
macro_data %>% chart_indicators("Inflation")
Core Indicators
macro_data %>% chart_indicators("Others")
Employment
macro_data %>% chart_indicators("Employment")
Housing & construction
macro_data %>% chart_indicators("Housing & construction")
Retail and Consumption
macro_data %>% chart_indicators("Retail and Consumption")
Surveys
macro_data %>% chart_indicators("Surveys")
Manufacturing
macro_data %>% chart_indicators("Manufacturing")
Income
macro_data %>% chart_indicators("Income")
cap mkts
sector_ticks %>%
gather(etf_family,ticker,-(1:2)) %>%
select(etf_family,sector,ticker,weight) %>%
mutate(prices = map(ticker,tidyquant::tq_get)) %>%
plot_index_splines()
/*fix for 0 padding*/
.col-1-2, .col-6-12 {
padding: 0.5%;
}
// add in last updated date
function get_time_diff( datetime ){
var datetime = new Date(datetime.replace(" ", "T") + "Z").getTime();;
var now = new Date().getTime();
var milisec_diff = now - datetime;
var msec = milisec_diff;
var hh = Math.floor(msec / 1000 / 60 / 60);
msec -= hh * 1000 * 60 * 60;
var mm = Math.floor(msec / 1000 / 60);
msec -= mm * 1000 * 60;
var ss = Math.floor(msec / 1000);
msec -= ss * 1000;
return hh + " Hours " + mm + " Minutes " + ss + " Seconds";
}
// resize highcharts to fit in main cotent area
document.addEventListener("DOMContentLoaded", function() {
$(".highchart, .highcharts-container, .highcharts-root").css("max-width","100%");
var t = setInterval(function(){
var resizeEvent = new Event('resize');
window.dispatchEvent(resizeEvent);
}, 1000);
});