From 158475d32c541ef9a7dd6bec54e127df8d65dd36 Mon Sep 17 00:00:00 2001 From: Matthew Grainger Date: Tue, 18 Jun 2024 09:17:50 +0200 Subject: [PATCH] Update app_server.R Fixing the error on start "Error in switch: EXPR must be a length 1 vector" where the switch is expecting either a ris or txt file but as none have been uploaded yet it gives an error. --- R/app_server.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/R/app_server.R b/R/app_server.R index 83f2712..f44c1c1 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -40,13 +40,22 @@ app_server <- function(input, output, session) { # reactive variables rawdata <- reactive({ - req(input$upload) + req(input$upload) # Ensure the file is uploaded + ext <- tools::file_ext(input$upload$name) - switch(ext, - txt = create_testset(input$upload$datapath), - ris = create_testset(input$upload$datapath), - validate("Invalid file: Please upload a risfile exported from Endnote or PubMed") + + # Ensure ext is a single value and handle invalid file extensions + if (length(ext) != 1 || ext == "") { + validate("Please upload a file") + } + + result <- switch(ext, + txt = create_testset(input$upload$datapath), + ris = create_testset(input$upload$datapath), + validate("Invalid file: Please upload a ris file exported from Endnote or PubMed") ) + + result }) allRefsTable <- reactive({ columns <- c("accession", "author", "year", "title")