# The first filter applied is the Result Date df2 <- raw.data() %>% subset(Date >= input$daterange[1] & Date <= input$daterange[2]) # The "Select Test" and "Select Analyzer" dropdown boxes are reactive. Here the script defines what should be displayed and filtered based on the various inputs. if(input$test == "" & input$analyzer == "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Date >= input$daterange[1] & Date <= input$daterange[2]) # updateSelectInput updates the selectInput dropdown boxes in the UI above. This allows interactivity between the two lists, which is nice when you have lots of tests. updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df2$Test))) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df2$Analyzer))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df2$QC_Mnemonic))) } # Now apply various filters when the selectInput box has a chosen Test or Analyzer, and update the selections available for the Analyzer else if(input$test != "" & input$analyzer == "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Test == input$test & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test == "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test != "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Test == input$test & Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test != "" & input$analyzer != "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Test == input$test & Analyzer == input$analyzer & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) } else if(input$test == "" & input$analyzer != "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) } else if(input$test == "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test == "" & input$analyzer == "" & input$qcproduct != ""){ df3 <- df2 %>% subset(QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) } return(df4) }) ########################################################################################################################### # End of filter application. At this point, all raw data has been processed according to the filters applied ########################################################################################################################### summary.data <- reactive({ # Now we will generate the summary data # First, format the Day, Week, and Month columns for summary df4 <- filter.data() %>% mutate( Date = ymd_hms(Date), Day = floor_date(Date, unit = "days"), Week = floor_date(Date, unit = "week"), Month = floor_date(Date, unit = "month") ) df4 <- df4 %>% mutate( Day = as.Date(Day), Week = as.Date(Week), Month = as.Date(Month) ) if(input$timeframe == 1){ p4 <- df4 %>% group_by(Day, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } else if(input$timeframe == 2){ p4 <- df4 %>% group_by(Week, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } else if(input$timeframe == 3){ p4 <- df4 %>% group_by(Month, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } return(p4) }) #Generates the output table wich is displayed in the Summary Tab output$sumtable <- renderDT( datatable(summary.data(), rownames = FALSE) ) ########################################################################################################################### # End of "Summary" tab data. ########################################################################################################################### output$chart <- renderPlotly({ plot.data <- summary.data() %>% ungroup() validate( need(input$qcproduct != "", "Please Select QC Product") ) if(input$timeframe == 1){ p <- plot_ly(data = plot.data, x = ~Day, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } else if (input$timeframe == 2) { p <- plot_ly(data = plot.data, x = ~Week, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } else if (input$timeframe == 3) { p <- plot_ly(data = plot.data, x = ~Month, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } }) } # Run the application shinyApp(ui = ui, server = server) server <- function(session, input, output) { raw.data <- reactive({ # Tell user to select QC data if none selected validate( need(!is.null(input$datainput$datapath), "Select QC Data File") ) #if the file import filter is not empty, the user has imported different data files, so make a new list list <- input$datainput$datapath # same as above, but no need to sort raw.qcdata <- do.call("rbind", lapply(list, function(x) read.csv(x, stringsAsFactors = FALSE))) # Format the date column, same as above raw.qcdata$Date <- ymd_hms(raw.qcdata$Date) # Tell the date range box in the UI what ranges it can display updateDateRangeInput(session, "daterange", "Select Date Range:", min = min(round_date(raw.qcdata$Date, unit = "days")), max = max(round_date(raw.qcdata$Date, unit = "days")), start = min(round_date(raw.qcdata$Date, unit = "days")), end = max(round_date(raw.qcdata$Date, unit = "days")) ) # Tells R to assign the imported data to the reactive variable raw.data return(raw.qcdata) }) filter.data <- reactive({ # The first filter applied is the Result Date df2 <- raw.data() %>% subset(Date >= input$daterange[1] & Date <= input$daterange[2]) # The "Select Test" and "Select Analyzer" dropdown boxes are reactive. Here the script defines what should be displayed and filtered based on the various inputs. if(input$test == "" & input$analyzer == "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Date >= input$daterange[1] & Date <= input$daterange[2]) # updateSelectInput updates the selectInput dropdown boxes in the UI above. This allows interactivity between the two lists, which is nice when you have lots of tests. updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df2$Test))) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df2$Analyzer))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df2$QC_Mnemonic))) } # Now apply various filters when the selectInput box has a chosen Test or Analyzer, and update the selections available for the Analyzer else if(input$test != "" & input$analyzer == "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Test == input$test & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test == "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test != "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Test == input$test & Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test != "" & input$analyzer != "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Test == input$test & Analyzer == input$analyzer & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) } else if(input$test == "" & input$analyzer != "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) } else if(input$test == "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test == "" & input$analyzer == "" & input$qcproduct != ""){ df3 <- df2 %>% subset(QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) } return(df3) }) ########################################################################################################################### # End of filter application. At this point, all raw data has been processed according to the filters applied ########################################################################################################################### summary.data <- reactive({ # Now we will generate the summary data # First, format the Day, Week, and Month columns for summary df4 <- filter.data() %>% mutate( Date = ymd_hms(Date), Day = floor_date(Date, unit = "days"), Week = floor_date(Date, unit = "week"), Month = floor_date(Date, unit = "month") ) df4 <- df4 %>% mutate( Day = as.Date(Day), Week = as.Date(Week), Month = as.Date(Month) ) if(input$timeframe == 1){ p4 <- df4 %>% group_by(Day, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } else if(input$timeframe == 2){ p4 <- df4 %>% group_by(Week, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } else if(input$timeframe == 3){ p4 <- df4 %>% group_by(Month, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } return(p4) }) #Generates the output table wich is displayed in the Summary Tab output$sumtable <- renderDT( datatable(summary.data(), rownames = FALSE) ) ########################################################################################################################### # End of "Summary" tab data. ########################################################################################################################### output$chart <- renderPlotly({ plot.data <- summary.data() %>% ungroup() validate( need(input$qcproduct != "", "Please Select QC Product") ) if(input$timeframe == 1){ p <- plot_ly(data = plot.data, x = ~Day, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } else if (input$timeframe == 2) { p <- plot_ly(data = plot.data, x = ~Week, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } else if (input$timeframe == 3) { p <- plot_ly(data = plot.data, x = ~Month, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } }) } # Run the application shinyApp(ui = ui, server = server) server <- function(session, input, output) { raw.data <- reactive({ # Tell user to select QC data if none selected validate( need(!is.null(input$datainput$datapath), "Select QC Data File") ) #if the file import filter is not empty, the user has imported different data files, so make a new list list <- input$datainput$datapath # same as above, but no need to sort raw.qcdata <- do.call("rbind", lapply(list, function(x) read.csv(x, stringsAsFactors = FALSE))) # Format the date column, same as above raw.qcdata$Date <- ymd_hms(raw.qcdata$Date) # Tell the date range box in the UI what ranges it can display updateDateRangeInput(session, "daterange", "Select Date Range:", min = min(round_date(raw.qcdata$Date, unit = "days")), max = max(round_date(raw.qcdata$Date, unit = "days")), start = min(round_date(raw.qcdata$Date, unit = "days")), end = max(round_date(raw.qcdata$Date, unit = "days")) ) # Tells R to assign the imported data to the reactive variable raw.data return(raw.qcdata) }) filter.data <- reactive({ # The first filter applied is the Result Date df2 <- raw.data() %>% subset(Date >= input$daterange[1] & Date <= input$daterange[2]) # The "Select Test" and "Select Analyzer" dropdown boxes are reactive. Here the script defines what should be displayed and filtered based on the various inputs. if(input$test == "" & input$analyzer == "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Date >= input$daterange[1] & Date <= input$daterange[2]) # updateSelectInput updates the selectInput dropdown boxes in the UI above. This allows interactivity between the two lists, which is nice when you have lots of tests. updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df2$Test))) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df2$Analyzer))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df2$QC_Mnemonic))) } # Now apply various filters when the selectInput box has a chosen Test or Analyzer, and update the selections available for the Analyzer else if(input$test != "" & input$analyzer == "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Test == input$test & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test == "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test != "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Test == input$test & Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test != "" & input$analyzer != "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Test == input$test & Analyzer == input$analyzer & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) } else if(input$test == "" & input$analyzer != "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) } else if(input$test != "" & input$analyzer == "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Test == input$test & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test == "" & input$analyzer == "" & input$qcproduct != ""){ df3 <- df2 %>% subset(QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) } return(df3) }) ########################################################################################################################### # End of filter application. At this point, all raw data has been processed according to the filters applied ########################################################################################################################### summary.data <- reactive({ # Now we will generate the summary data # First, format the Day, Week, and Month columns for summary df4 <- filter.data() %>% mutate( Date = ymd_hms(Date), Day = floor_date(Date, unit = "days"), Week = floor_date(Date, unit = "week"), Month = floor_date(Date, unit = "month") ) df4 <- df4 %>% mutate( Day = as.Date(Day), Week = as.Date(Week), Month = as.Date(Month) ) if(input$timeframe == 1){ p4 <- df4 %>% group_by(Day, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } else if(input$timeframe == 2){ p4 <- df4 %>% group_by(Week, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } else if(input$timeframe == 3){ p4 <- df4 %>% group_by(Month, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } return(p4) }) #Generates the output table wich is displayed in the Summary Tab output$sumtable <- renderDT( datatable(summary.data(), rownames = FALSE) ) ########################################################################################################################### # End of "Summary" tab data. ########################################################################################################################### output$chart <- renderPlotly({ plot.data <- summary.data() %>% ungroup() validate( need(input$qcproduct != "", "Please Select QC Product") ) if(input$timeframe == 1){ p <- plot_ly(data = plot.data, x = ~Day, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } else if (input$timeframe == 2) { p <- plot_ly(data = plot.data, x = ~Week, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } else if (input$timeframe == 3) { p <- plot_ly(data = plot.data, x = ~Month, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } }) } # Run the application shinyApp(ui = ui, server = server) server <- function(session, input, output) { raw.data <- reactive({ # Tell user to select QC data if none selected validate( need(!is.null(input$datainput$datapath), "Select QC Data File") ) #if the file import filter is not empty, the user has imported different data files, so make a new list list <- input$datainput$datapath # same as above, but no need to sort raw.qcdata <- do.call("rbind", lapply(list, function(x) read.csv(x, stringsAsFactors = FALSE))) # Format the date column, same as above raw.qcdata$Date <- ymd_hms(raw.qcdata$Date) # Tell the date range box in the UI what ranges it can display updateDateRangeInput(session, "daterange", "Select Date Range:", min = min(round_date(raw.qcdata$Date, unit = "days")), max = max(round_date(raw.qcdata$Date, unit = "days")), start = min(round_date(raw.qcdata$Date, unit = "days")), end = max(round_date(raw.qcdata$Date, unit = "days")) ) # Tells R to assign the imported data to the reactive variable raw.data return(raw.qcdata) }) filter.data <- reactive({ # The first filter applied is the Result Date df2 <- raw.data() %>% subset(Date >= input$daterange[1] & Date <= input$daterange[2]) # The "Select Test" and "Select Analyzer" dropdown boxes are reactive. Here the script defines what should be displayed and filtered based on the various inputs. if(input$test == "" & input$analyzer == "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Date >= input$daterange[1] & Date <= input$daterange[2]) # updateSelectInput updates the selectInput dropdown boxes in the UI above. This allows interactivity between the two lists, which is nice when you have lots of tests. updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df2$Test))) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df2$Analyzer))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df2$QC_Mnemonic))) } # Now apply various filters when the selectInput box has a chosen Test or Analyzer, and update the selections available for the Analyzer else if(input$test != "" & input$analyzer == "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Test == input$test & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test == "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test != "" & input$analyzer != "" & input$qcproduct == ""){ df3 <- df2 %>% subset(Test == input$test & Analyzer == input$analyzer & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "qcproduct", "Select QC Product:", choices = c("", unique(df3$QC_Mnemonic))) } else if(input$test != "" & input$analyzer != "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Test == input$test & Analyzer == input$analyzer & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) } else if(input$test == "" & input$analyzer != "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Analyzer == input$analyzer & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) } else if(input$test != "" & input$analyzer == "" & input$qcproduct != ""){ df3 <- df2 %>% subset(Test == input$test & QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) } else if(input$test == "" & input$analyzer == "" & input$qcproduct != ""){ df3 <- df2 %>% subset(QC_Mnemonic == input$qcproduct & Date >= input$daterange[1] & Date <= input$daterange[2]) updateSelectInput(session, "test", "Select Test:", choices = c("", unique(df3$Test))) updateSelectInput(session, "analyzer", "Select Analyzer:", choices = c("", unique(df3$Analyzer))) } return(df3) }) ########################################################################################################################### # End of filter application. At this point, all raw data has been processed according to the filters applied ########################################################################################################################### summary.data <- reactive({ # Now we will generate the summary data # First, format the Day, Week, and Month columns for summary df4 <- filter.data() %>% mutate( Date = ymd_hms(Date), Day = floor_date(Date, unit = "days"), Week = floor_date(Date, unit = "week"), Month = floor_date(Date, unit = "month") ) df4 <- df4 %>% mutate( Day = as.Date(Day), Week = as.Date(Week), Month = as.Date(Month) ) if(input$timeframe == 1){ p4 <- df4 %>% group_by(Day, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } else if(input$timeframe == 2){ p4 <- df4 %>% group_by(Week, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } else if(input$timeframe == 3){ p4 <- df4 %>% group_by(Month, Test, Analyzer, QC_Mnemonic) %>% summarize(N = length(Result), Mean = round(mean(Result), 2), SD = round(sd(Result), 3), "%CV" = round(100*SD/Mean, 2)) } return(p4) }) #Generates the output table wich is displayed in the Summary Tab output$sumtable <- renderDT( datatable(summary.data(), rownames = FALSE) ) ########################################################################################################################### # End of "Summary" tab data. ########################################################################################################################### output$chart <- renderPlotly({ plot.data <- summary.data() %>% ungroup() validate( need(input$qcproduct != "", "Please Select QC Product") ) if(input$timeframe == 1){ p <- plot_ly(data = plot.data, x = ~Day, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } else if (input$timeframe == 2) { p <- plot_ly(data = plot.data, x = ~Week, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } else if (input$timeframe == 3) { p <- plot_ly(data = plot.data, x = ~Month, y = ~Mean, type = 'scatter', mode = 'lines+markers', error_y = ~list(array = SD, color = '#000000') ) } }) } # Run the application shinyApp(ui = ui, server = server)