+ },
+ error = function(e) {
+ output[[paste0(data_source, "_warn")]] <- renderText(
+ "The input does not match the required format."
+ )
+ }
+ )
+}
+
+# Load sample datasets.
+load_samples <- function(input, output, react_values) {
+ observeEvent(input$data_samples, {
+ names <- c()
+ units <- c()
+ counts <- c()
+
+ # COVID-19 Canada, March 2020 (weekly).
+ if (input$covid_canada) {
+ names <- c(names, "COVID-19 Canada 2020/03/03 - 2020/03/31")
+ units <- c(units, "Weeks")
+ counts <- c(counts, toString(Rnaught::COVIDCanada[seq(41, 69, 7), 2]))
+ }
+ # COVID-19 Ontario, March 2020 (weekly).
+ if (input$covid_ontario) {
+ names <- c(names, "COVID-19 Ontario 2020/03/03 - 2020/03/31")
+ units <- c(units, "Weeks")
+ counts <- c(counts,
+ toString(Rnaught::COVIDCanadaPT[seq(10176, 10204, 7), 3])
+ )
+ }
+
+ if (length(names) == 0) {
+ output$data_samples_warn <- renderText(
+ "At least one sample dataset must be selected."
+ )
+ } else if (any(names %in% react_values$data_table[, 1])) {
+ output$data_samples_warn <- renderText(
+ "At least one of the selected dataset names already exist."
+ )
+ } else {
+ output$data_samples_warn <- renderText("")
+
+ new_rows <- data.frame(names, units, counts)
+ colnames(new_rows) <- c("Name", "Time units", "Case counts")
+ react_values$data_table <- rbind(react_values$data_table, new_rows)
+
+ # Evaluate all existing estimators on the sample datasets and update the
+ # corresponding columns in the estimates table.
+ update_estimates_cols(new_rows, react_values)
+
+ showNotification("Datasets added successfully.", duration = 3)
+ }