####
# Author: Martin W. Goros
# UT Health San Antonio
# create redcap connection
rcon <- redcapAPI::redcapConnection(url=rc_url, token=rc_token)
# pulling data
full_data <- read_redcap(redcap_url=rc_url,secret_token=rc_token)
if(is.null(full_data)){
projectinfo <- NULL
job_phase <- NULL
work <- NULL
appt <- NULL
status <- NULL
# get current status
ticket_data <- plyr::ddply(status,"record_id",function(x){
x <- x[order(x$job_phase_date,na.last=FALSE),]
x <- x[nrow(x),]
return(x)
})
# tables displayed
InfoTable <- NULL
myTimeTable <- NULL
InfoTable <- NULL
# numbers for pie chart
PctPie <- data.frame(Phase=InfoTable$job_phase)
if(any(InfoTable$job_phase == 'Active')){
PctPieStaff <- data.frame(Staff=subset(InfoTable,job_phase %in% c('Active'))$assigned_staff)
PctPieStaff$Staff <- as.character(PctPieStaff$Staff)
PctPieStaff[(PctPieStaff$Staff == '') | is.na(PctPieStaff$Staff),] <- "No Staff"
}else{
PctPieStaff <- "No active project"
PctPieStaff <- data.frame(Staff=PctPieStaff)
}
# dashboard status numbers
intakes <- nrow(subset(ticket_data,job_phase == 'Intake'))
actives <- nrow(subset(ticket_data,job_phase == 'Active'))
inactives <- nrow(subset(ticket_data,job_phase == 'Inactive'))
hold <- nrow(subset(ticket_data,job_phase == 'Hold'))
grant <- nrow(subset(ticket_data,job_phase == 'Grant Writing'))
manus <- nrow(subset(ticket_data,job_phase == 'Manuscript Writing'))
total <- sum(actives,inactives,hold,grant,manus)
}else{
full_data$job_phase_date <- as.POSIXct(as.character(full_data$job_phase_date),format="%Y-%m-%d %H:%M:%S")
full_data$contribution_date <- as.POSIXct(as.character(full_data$contribution_date),format="%Y-%m-%d %H:%M:%S")
if(is.null(full_data$redcap_repeat_instrument)){
full_data$redcap_repeat_instrument <- NA
}
projectinfo <- subset(full_data,select=c('record_id','redcap_repeat_instrument','job_title','job_alias','job_description','job_start_date','job_end_date','assigned_faculty','assigned_staff','pi_name','pi_department','requestor_email','data_source','funding_type','estimated_hours','importance','h_index','modifier_job','deadline_date'))
projectinfo <- subset(projectinfo,!(redcap_repeat_instrument %in% c('job_phase','work','research_outcome')))
job_phase <- subset(full_data,select=c('record_id','redcap_repeat_instrument','job_phase','job_phase_date','job_phase_comment','modifier_job_phase'))
job_phase <- subset(job_phase,!(redcap_repeat_instrument %in% c('','work','research_outcome')))
work <- subset(full_data,select=c('record_id','work_description','redcap_repeat_instrument','hours','billable','contribution_date','modifier_work','work_complete'))
work <- subset(work,!(redcap_repeat_instrument %in% c('','job_phase','research_outcome')))
appt <- subset(full_data,select=c('record_id','faculty_appt','date_appt','note_appt','modifier_appt'))
status <- plyr::join(projectinfo,job_phase,by='record_id')
status <- subset(status,select=c('record_id','job_title','job_alias','job_phase','job_phase_date','deadline_date','job_phase_comment','assigned_faculty','assigned_staff','pi_name','requestor_email','pi_department','funding_type','estimated_hours','importance','h_index'))
status <- subset(status,job_title != "")
# get current status
ticket_data <- plyr::ddply(status,"record_id",function(x){
x <- x[order(x$job_phase_date,na.last=FALSE),]
x <- x[nrow(x),]
return(x)
})
# tables displayed
InfoTable <- ticket_data
myTimeTable <- ticket_data
InfoTable <- subset(InfoTable,job_phase != "Completed")
# numbers for pie chart
PctPie <- data.frame(Phase=InfoTable$job_phase)
if(any(InfoTable$job_phase == 'Active')){
PctPieStaff <- data.frame(Staff=subset(InfoTable,job_phase %in% c('Active'))$assigned_staff)
PctPieStaff$Staff <- as.character(PctPieStaff$Staff)
PctPieStaff[(PctPieStaff$Staff == '') | is.na(PctPieStaff$Staff),] <- "No Staff"
}else{
PctPieStaff <- "No active project"
PctPieStaff <- data.frame(Staff=PctPieStaff)
}
# dashboard status numbers
intakes <- nrow(subset(ticket_data,job_phase == 'Intake'))
actives <- nrow(subset(ticket_data,job_phase == 'Active'))
inactives <- nrow(subset(ticket_data,job_phase == 'Inactive'))
hold <- nrow(subset(ticket_data,job_phase == 'Hold'))
grant <- nrow(subset(ticket_data,job_phase == 'Grant Writing'))
manus <- nrow(subset(ticket_data,job_phase == 'Manuscript Writing'))
total <- sum(intakes,actives,inactives,hold,grant,manus)
}
### END ###
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.