server = shinyServer(function(input, output,session){
##########################################################################################################################################################################################################################################################################
########FILE UPLOAD#############################################################################################################################################################################################################
##########################################################################################################################################################################################################################################################################
#FILE UPLOAD:
observeEvent(input$import, {
file1 <- input$import
server_data <- read.delim(file=file1$datapath, header = TRUE, na.strings=c(""," ","NA"))
#Create a subset of the data to remove/exclude the unnecessary columns:
subset_data_server <- server_data[,c(-5,-7,-9,-17,-25:-31)]
#Remove the rows with blank/NA values:
df1 <- na.omit(subset_data_server)
#The difference between the ResultTime and the FirstScanTime is the turn around time:
df1$TS_start <- paste(df1$FirstScanDate, df1$FirstScanTime)
df1$TS_end <- paste(df1$ResultDate, df1$ResultTime)
df1$TAT <- difftime(df1$TS_end,df1$TS_start,units = "mins")
#Compute the difference in Firstscan time and test registration time, if this is positive, the order is create before the scan
#thus a regular test, if this is negative the order is create after the sample is in the lab, this is an upon request:
df1$TS_request <- paste(df1$TestRegistrationDate, df1$TestRegistrationTime)
df1$upon_requestTime <- difftime(df1$TS_start, df1$TS_request, units = "mins")
df1$upon_request <- sub('mins','',df1$upon_requestTime)
df1$upon_request<-replace(df1$upon_request, df1$upon_request>0,"no")
df1$upon_request<-replace(df1$upon_request, df1$upon_request<0,"yes")
#write.csv(df1, "G:/My Drive/Traineeship Advanced Bachelor of Bioinformatics 2022/Internship 2022-2023/internship documents\\df1.csv", row.names = TRUE)
#Extract the date of the data out of the file
output$date <- renderText(
server_data[2, 'FirstScanDate']
)
##########################################################################################################################################################################################################################################################################
########DISTRIBUTION Over the DAY#############################################################################################################################################################################################################
##########################################################################################################################################################################################################################################################################
#DISTRIBUTION:
updateSelectizeInput(session, 'material', choices = df1$Material, server = TRUE)
output$barplot1 <- renderPlot({
if (input$material!=""){
df1_filtered <- df1[df1$Material == input$material,]
#Calculate the amount of Result-samples each hour:
hours_set <- hms(df1_filtered$ResultTime)
df2 <- as.data.frame(hours_set$hour)
df_aggr_Result <- aggregate(df2, by=list(df2$`hours_set$hour`), FUN = length)
#Renaming
names(df_aggr_Result)[names(df_aggr_Result) == "Group.1"] <- "hour"
names(df_aggr_Result)[names(df_aggr_Result) == "hours_set$hour"] <- "amount of samples"
all_h <- tibble(hour = 0:23)
df_plot = merge(x=all_h,y=df_aggr_Result,by="hour",all=TRUE)
df_plot[is.na(df_plot)] <- 0
ggplot(df_plot, aes(x = df_plot$hour, y = df_plot$`amount of samples`)) +
geom_bar(fill = "#0073C2FF", stat = "identity") +
theme(axis.text.x = element_text(face = "bold", color = "#993333", size = 15),
axis.text.y = element_text(face = "bold", color = "#993333", size = 15),
axis.line = element_line(color = "#993333", size = 1)) +
scale_x_continuous(breaks=seq(0,23,1)) +
xlab("Hours in a day") + ylab("Amount of samples")
}
})
updateSelectizeInput(session, 'test', choices = df1$TestName, server = TRUE)
output$barplot2 <- renderPlot({
if (input$test!=""){
df1_filtered <- df1[df1$TestName == input$test,]
#Calculate the amount of Result-samples each hour:
hours_set <- hms(df1_filtered$ResultTime)
df2 <- as.data.frame(hours_set$hour)
df_aggr_Result <- aggregate(df2, by=list(df2$`hours_set$hour`), FUN = length)
#Renaming
names(df_aggr_Result)[names(df_aggr_Result) == "Group.1"] <- "hour"
names(df_aggr_Result)[names(df_aggr_Result) == "hours_set$hour"] <- "amount of samples"
all_h <- tibble(hour = 0:23)
df_plot = merge(x=all_h,y=df_aggr_Result,by="hour",all=TRUE)
df_plot[is.na(df_plot)] <- 0
ggplot(df_plot, aes(x = df_plot$hour, y = df_plot$`amount of samples`)) +
geom_bar(fill = "#0073C2FF", stat = "identity") +
theme(axis.text.x = element_text(face = "bold", color = "#993333", size = 15),
axis.text.y = element_text(face = "bold", color = "#993333", size = 15),
axis.line = element_line(color = "#993333", size = 1)) +
scale_x_continuous(breaks=seq(0,23,1)) +
xlab("Hours in a day") + ylab("Amount of samples")
}
})
updateCheckboxGroupInput(session, 'system', label = NULL, choices = sort(unique(df1$InstrumentName)),
selected = 1, inline = FALSE)
output$barplot3 <- renderPlot({
if(input$all_cobas == TRUE) {
df1_filtered <- df1[grep("cobas", df1$InstrumentName), ]
}
else {
df1_filtered <- df1[df1$InstrumentName %in% input$system,]
}
#Calculate the amount of Result-samples each hour:
hours_set <- hms(df1_filtered$ResultTime)
df2 <- as.data.frame(hours_set$hour)
df_aggr_Result <- aggregate(df2, by=list(df2$`hours_set$hour`), FUN = length)
#Renaming
names(df_aggr_Result)[names(df_aggr_Result) == "Group.1"] <- "hour"
names(df_aggr_Result)[names(df_aggr_Result) == "hours_set$hour"] <- "amount of samples"
all_h <- tibble(hour = 0:23)
df_plot = merge(x=all_h,y=df_aggr_Result,by="hour",all=TRUE)
df_plot[is.na(df_plot)] <- 0
ggplot(df_plot, aes(x = df_plot$hour, y = df_plot$`amount of samples`)) +
geom_bar(fill = "#0073C2FF", stat = "identity") +
theme(axis.text.x = element_text(face = "bold", color = "#993333", size = 15),
axis.text.y = element_text(face = "bold", color = "#993333", size = 15),
axis.line = element_line(color = "#993333", size = 1)) +
scale_x_continuous(breaks=seq(0,23,1)) +
xlab("Hours in a day") + ylab("Amount of samples")
})
updateSelectizeInput(session, 'location', choices = df1$SourceDesc, server = TRUE)
output$barplot4 <- renderPlot({
if (input$location!=""){
df1_filtered <- df1[df1$SourceDesc == input$location,]
#Calculate the amount of Result-samples each hour:
hours_set <- hms(df1_filtered$ResultTime)
df2 <- as.data.frame(hours_set$hour)
df_aggr_Result <- aggregate(df2, by=list(df2$`hours_set$hour`), FUN = length)
#Renaming
names(df_aggr_Result)[names(df_aggr_Result) == "Group.1"] <- "hour"
names(df_aggr_Result)[names(df_aggr_Result) == "hours_set$hour"] <- "amount of samples"
all_h <- tibble(hour = 0:23)
df_plot = merge(x=all_h,y=df_aggr_Result,by="hour",all=TRUE)
df_plot[is.na(df_plot)] <- 0
ggplot(df_plot, aes(x = df_plot$hour, y = df_plot$`amount of samples`)) +
geom_bar(fill = "#0073C2FF", stat = "identity") +
theme(axis.text.x = element_text(face = "bold", color = "#993333", size = 15),
axis.text.y = element_text(face = "bold", color = "#993333", size = 15),
axis.line = element_line(color = "#993333", size = 1)) +
scale_x_continuous(breaks=seq(0,23,1)) +
xlab("Hours in a day") + ylab("Amount of samples")
}
})
updateSelectizeInput(session, 'validation', choices = df1$ValidationUser, server = TRUE)
output$barplot5 <- renderPlot({
if (input$validation!=""){
df1_filtered <- df1[df1$ValidationUser == input$validation,]
#Calculate the amount of Result-samples each hour:
hours_set <- hms(df1_filtered$ResultTime)
df2 <- as.data.frame(hours_set$hour)
df_aggr_Result <- aggregate(df2, by=list(df2$`hours_set$hour`), FUN = length)
#Renaming
names(df_aggr_Result)[names(df_aggr_Result) == "Group.1"] <- "hour"
names(df_aggr_Result)[names(df_aggr_Result) == "hours_set$hour"] <- "amount of samples"
all_h <- tibble(hour = 0:23)
df_plot = merge(x=all_h,y=df_aggr_Result,by="hour",all=TRUE)
df_plot[is.na(df_plot)] <- 0
ggplot(df_plot, aes(x = df_plot$hour, y = df_plot$`amount of samples`)) +
geom_bar(fill = "#0073C2FF", stat = "identity") +
theme(axis.text.x = element_text(face = "bold", color = "#993333", size = 15),
axis.text.y = element_text(face = "bold", color = "#993333", size = 15),
axis.line = element_line(color = "#993333", size = 1)) +
scale_x_continuous(breaks=seq(0,23,1)) +
xlab("Hours in a day") + ylab("Amount of samples")
}
})
})
})
This is the link to the df1.csv:
https://drive.google.com/file/d/1YsicgQdnSM5Iy4xOmAmdtqQDeXx5LRlZ/view?usp=share_link