Skip to content

Error in saveRDS in save_function_to_temp #292

@trafficonese

Description

@trafficonese

In an R Shiny App I got a bug like this, which points to this function

save_function_to_temp <- function(options) {

Warnung: Error in saveRDS: Schreibfehler in Verbindung
  95: h
  94: .handleSimpleError
  93: saveRDS
  92: withCallingHandlers
  91: suppressWarnings
  90: save_function_to_temp
  89: eval
  88: eval
  87: within.list
  86: within
  85: setup_script_files
  84: rp_init
  83: initialize
  82: r_process$new
  81: r_bg
  80: eval
  79: eval
  78: with_stealth_rng
  77: run.CallrFuture
  76: run
  75: run.Future
  74: run
  73: future
  72: observe [/root/server.R#4833]

and the relevant part in server.R looks like this:

observeEvent(input$saveDB, ignoreNULL = TRUE, ignoreInit = TRUE,  {
  progress = AsyncProgress$new(message="Save Changes")
  
  myFuture <- future(seed = NULL, label = "SaveToDatabase", {
    progress$inc(0.1, message = "Connect to DB")
    con_fut <- dbConnect(drv = RPostgres::Postgres(),
                         dbname   = GLOBALS[["db"]][["dbname"]],
                         host     = GLOBALS[["db"]][["dbhost"]],
                         port     = GLOBALS[["db"]][["dbport"]],
                         user     = GLOBALS[["db"]][["dbuser"]],
                         password = GLOBALS[["db"]][["dbpwd"]],
                         bigint  = "integer",
                         timezone = "CET",
                         timezone_out = "CET")
    on.exit(dbDisconnect(con_fut), add = TRUE)
    progress$inc(0.1, message = "DB connected. Save changes.")
    handle_changes(con_fut, current_changes, tablename, progress)  ## separate function to create SQL UPDATEs and execute them
  })
  then(
    myFuture,
    onFulfilled = function(value) {
      if (!is.null(value$errors)) {
        showNotification(unique(value$errors)[[1]], session = session, type = "error")
      }
      progress$close()
    },
    onRejected = function(reason) {
      showNotification("Could not save changes", session = session, type = "error")
      progress$close()
      write("Changes saved successfully", file = logfile, append = TRUE)
    }
  )
  return(NULL)
})

Unfortunately I dont have a reproducible example, but its a bit tricky with the DB and the SQL-creation function, but I thought maybe you have an idea why that error happens?

Metadata

Metadata

Assignees

No one assigned

    Labels

    reprexneeds a minimal reproducible example

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions