0

I have developed an R Shiny App hosted using rconnect. The app uses the pins library to store user inputs in a table, which is then pinned to my rconnect board. On app start, the pinned table is read to retrieve existing data and display it. Surprisingly, the initial read operation after this "initial read" takes an unexpectedly long time of around 15 minutes, but subsequent reads and all subsequent operations take only about 1 second.

Here are the steps that occur:

App starts, the pin is read, and the data is displayed (1 second). The user inputs data and clicks "save changes". The saving process begins: The current version of the pin is read again to ensure no other user made changes. A row with the user inputs is appended to the dataframe created from the previously read pin. The pin is overwritten with the new appended table. The issue arises during step 1 of the saving process (reading the pin again) after a prolonged period of not using the app. This initial read operation takes 15 minutes, but subsequent reads, even if the app is closed and reopened, only take 1 second. This problem occurs only after several hours of app inactivity.

I would appreciate any assistance in understanding why the initial read takes significantly longer than subsequent reads, especially since the pin was already read at app start, making it technically the second read.

The pin has a type of "qs". Here is the code for my saving function:

R

save_changes <- function(df) {
    
    cat(paste(Sys.time(), "Start reading pin \n"))
    current_pin <- pin_read(board, "PIN-NAME")
    cat(paste(Sys.time(), "Pin read \n"))
    
    pin_to_save <- rbind(current_pin, df)
    cat(paste(Sys.time(), "Writing ", nrow(pin_to_save), "rows as a new Pin. Starting... \n"))
    pin_write(board, pin_to_save, name = "PIN-NAME", title = "PIN-TITLE", type = "qs")
    cat(paste(Sys.time(), "Finished. \n"))
    
    return("Saved")
    
}

The console output typically looks like this:

Copy code
2023-06-30 07:36:51 Start reading pin 
2023-06-30 07:36:51 Pin read 
2023-06-30 07:36:51 Writing  7 rows as a new Pin. Starting... 
2023-06-30 07:36:52 Finished. 

And after a longer period of app inactivity:

Copy code
2023-06-30 05:17:10 Start reading pin 
2023-06-30 05:33:27 Pin read 
2023-06-30 05:33:27 Writing  7 rows as a new Pin. Starting... 
2023-06-30 05:33:27 Finished.

I can reproduce this issue by simply not using the app for some time. Currently, I am the only user of this app. If I'm starting the app locally from my laptop, everything works fine (exactly like after deploying and not waiting).

Could someone please assist me in understanding why this one read takes so long and provide any suggestions for resolving this issue?

I tried deleting and recreating the pin. I tried redeploying the app. I tried all pin types.

r2evans
  • 141,215
  • 6
  • 77
  • 149
Lukas
  • 1
  • 1
    This might be more appropriate for Posit Community and/or a bug report to the [`pins` package](https://github.com/rstudio/pins-r). – r2evans Jun 30 '23 at 13:15

0 Answers0