This is my contribution to the fields of data science, business analytics, information technology, and related topics.
# here I manually define which blog posts to include
blog_df <- data.frame(
filename = c("create_interesting_datasets"
,"ifelse_NA_trap"
,"building_this_site"
# ,"ed_api"
,"monty_hall"
,"Report")
)
# eventually, I will read all .rmd files in main dir
# and exclude non-blog posts because blog posts will
# quickly outnumber non-blog posts
# pull some text from each post for a content sample
blog_df <- blog_df %>%
mutate(intro = sapply(
paste0(blog_df$filename,".Rmd"),function(x){
paste0(substr(gsub(".*##",
"",
paste(readLines(x)[1:100],collapse = " "),
perl = TRUE
),
1,140)," ...")
}
)
, lines = sapply(
paste0(blog_df$filename,".Rmd"),function(x) blog_df$filename = length(readLines(x)))
, title = sapply(
paste0(blog_df$filename,".Rmd"),function(x){
gsub('"',
"",
gsub("title: ",
"",
readLines(x)[2]
)
)
}
)) %>%
bind_rows(data.frame(filename = 'ed_api'
,intro = 'Function for Easy Calling To help alleviate some of the headache, I wrote a function below that builds the call and traverses all pages ...'
,lines = 188
, title = 'Department of Ed API'))
# identify metadata
blog_df$created_at <- as.Date(file.info(paste0(blog_df$filename,".html"))$ctime)
blog_df$updated_at <- as.Date(file.info(paste0(blog_df$filename,".html"))$mtime)
blog_df$created_updated_at <- paste0(
blog_df$created_at
, " /<br>"
, blog_df$updated_at
)
#wrap filename in raw html
#use post title as visible text
blog_df$filename <- paste0(
"<h7> <a class='minimal' href='"
, blog_df$filename
, ".html' target='_blank'>"
, blog_df$title," "
, "<i class='fa fa-sign-in fa-lg'></i>","</a></h7>")
# no longer need plain text titles
blog_df$title <- NULL
blog_df <- blog_df %>%
arrange(desc(created_at)) %>%
select(filename,intro,created_updated_at,lines)
# define formate for header
col_format <- JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#252525', 'color': '#FFFFFF'});",
"}")
datatable(blog_df
,escape = FALSE
,rownames=FALSE
,colnames = c('Title',
'Content Snippet',
'Created / Updated',
# 'Created At',
# 'Updated At',
'Post Length (lines)')
,options=list(
autoWidth = TRUE,
initComplete = col_format,
pageLength=25,
columnDefs = list( # center all but first column
list(className = 'dt-center',targets=2)
, list(className = 'dt-right',targets=3)
, list(width = '100px', targets = c(2,3))
, list(width = '250px', targets = 0)
, list(verticalAlign = 'top', targets = "_all")),
dom = 'frtpB'
)) %>%
formatStyle(
'lines',
background = styleColorBar(range(0,max(blog_df$lines)), 'orange'),
align = 'bottom',
backgroundSize = '98% 45%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'left') %>%
formatStyle(columns = "filename",
color = 'black',
fontWeight = 'bold') %>%
formatStyle(names(blog_df), 'vertical-align'='top')