Guri Giaever
Guri Giaever

Reputation: 11

Is it possible to clear the Shiny cache when reloading an app?

Is it possible to clear the Shiny cache history when reloading an app? Specifically, I have a textInput for adding a title that doesn't clear when the app is restarted. In other words, all of the titles entered into the app on previous runs have been "remembered" and show up in a dropdown list when the app is rerun or restarted again. I have tried using shinyjs::reset, but that clears the current value and not the ones in the "history". I've also tried updateTextInput with an action button set to " ", but also clears only the current value and not the ones in the "history". I have also tried setting ui as a function using:

ui <- function(req) { fluidPage(...) }

as well as:

I found that cache of R Shiny server is updated when the date of creation for the file "app.R" is changed.

So, here is the trick I used:

server <- function(input, output, session) {

Trick file date creation update onStop(function() {

 # File name
 p <- paste0(getwd(), "/app.R")

 # Update file 'date creation'
 Sys.setFileTime(p, now())

}) # onStop

} # server The idea is to update the date of "app.R" creation after each session.

Neither of these solutions worked for me. Finally, I found this post:

I also found this post:

I have been struggling with this problem for quite a while, and thought I had tried everything, including putting a js button on the shiny sidebar to manually refresh (unfortunately that did not work either). There are two things that did work for me:

  1. Make sure all code to read data from files is NOT in a code chunk with a name OTHER THAN global OR

  2. Manually restart the shiny server when new data is uploaded

Obviously the first one is much more manageable, and a solution that I wish I had known weeks ago when I started playing with workarounds.

But I am not sure what is involved in implementing either, so if someone could clarify that, that would be great.

Any help would be much appreciated.

Upvotes: 1

Views: 2120

Answers (1)

user20863342
user20863342

Reputation: 1

after today, i fix it: follow this: frist:you should use crontab to make a time-work; then: add this R code: file_path <- "ui.R" ## remermer use Absolute Path and chmod 666 ui.R lines <- readLines(file_path) new_line <- paste0("print('up last time ", substr(as.character(Sys.time()), 1, 19), "')") lines <- c(new_line, lines) writeLines(lines, file_path)

Upvotes: 0

Related Questions