A function that has been working all the time now throws an error

The function in the server below has always worked fine, but lately it throws the error:
"Error in =: invalid (NULL) left side of assignment". it seems as no value is being returned from the glysoPipe() function and no value is being assigned to the receiving variable. I looked for information in Google and I found the following link: Error in { invalid (NULL) left side of the assignment | The Data Science Learner. There is not explanation to the problem. Could anyone help with this?

Blockquote

fluidPage(
verbatimTextOutput("theError")
)
glycoPipe <- function(infileName)
{  
    errorMessage = TRUE
    list(errorMessage = errorMessage)
}
server <- function(input, output){

  inFile <- reactive({input$file})
  inFileName <- reactive({input$file$name})
  
  output$contents <- renderTable({
    inFile <- input$file
    inFileName <- input$file$name
    if(input$btn){
      hide("btn")
    }
    
    if(is.null("inFile")){
      return()
    }
    
    req(inFile)
    validate( need(tools::file_ext(inFileName) %in% c(
      'tsv'
    ), "Wrong File Format. The selected file is not a valid tab-separated PARAMS file. Try again. If you do not have a parameters.tsv file in your directory stop clycoPipe create a file and re-start glycoPipe. Otherwise, you can download a PARAMS file by answering (N)  to the question (Do you have a parameters file ready to use) in the letf hand-side panel? Save this file to the directory of your choice, and stop and restart glycoPipe"))
    read.delim(inFile$datapath, quote = "", sep = '\t')
    #' When files get uploaded, their new filenames are gibberish.
    #' This function renames all uploaded files to their original names
    #' @param inFile The dataframe returned from a shiny::fileInput
    if (is.null(inFile)) {
      return()
    }
    
     oldNames = inFile$datapath
     newNames = file.path(dirname(inFile$datapath),inFile$name)
     file.rename(from = oldNames, to = newNames)
     inFileName <- inFile$datapath <- newNames
  })
  
 output$theError <- renderPrint({
    
    errormessage = glycoPipe(inFileName())
    errormessage$errorMessage
  })
}

I don't know what the exact cause of your error message is, but I see a number of issues with the code here, which could be related.

In the server function, you have the following reactive expressions:

  inFile <- reactive({input$file})
  inFileName <- reactive({input$file$name})

but then inside the renderTable(), you mask them, with regular values:

    inFile <- input$file
    inFileName <- input$file$name

So inside of the renderTable(), inFileName has some value, but in the renderPrint(), inFileName refers to a different object (the reactive expression).

    if(is.null("inFile")) {
       ...
    }

But "inFile" is never NULL. You probably want to test is.null(inFile) instead of is.null("inFile").

Later you do check for (is.null(inFile)), so perhaps you just want to keep one of the checks.

This assignment only modifies the local copies of inFile and inFileName, the ones inside of renderTable -- it won't affect the copies that are reactive expressions defined at the top of the server function.

inFileName <- inFile$datapath <- newNames

For debugging your problem, I suggest putting a browser() at the top of the renderTable() and renderPrint() code and then stepping through your code. See http://adv-r.had.co.nz/Exceptions-Debugging.html#debugging-tools for more information on how to use the debugger.

1 Like