R Shiny app shows old data

后端 未结 3 1422
无人及你
无人及你 2021-01-12 08:16

I have shiny app, which is displaying old data (4 days delay!) though on the server data are refreshed (current day).

What is strange the old dataset does not exist

相关标签:
3条回答
  • 2021-01-12 08:40

    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 in a code chunk with name 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.

    0 讨论(0)
  • 2021-01-12 08:42

    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.

    0 讨论(0)
  • 2021-01-12 08:43

    This is an old question, however, in case anyone has this issue and stumbles across this question here an answer embedded deep in the closed issues of the shiny development.

    Solution

    Your UI is probably not a function, and so it is being cached by Shiny for performance reasons. If you don't want the caching, just make it into a function (however, this does mean that you lose the slight performance benefit of UI caching).

    Turn this:

    ui <- fluidPage(...)
    

    into this:

    ui <- function(req) {
      fluidPage(...)
    }
    
    0 讨论(0)
提交回复
热议问题