简体   繁体   中英

How do I monitor a file system event within a Shiny app

How can I monitor a change to a file system (or other external event) in real time using a Shiny app? For example, suppose I have a dashboard app that provides statistics on files located on the server. I would like to update my statistics in real time as those files change or new ones are added.

My thought is to use Javascript on the client to regularly poll the server. Every 10 seconds, eg, I might call Shiny.setInputValue("check.fs", 1, {priority: "event"}); and then on the server I'd have observeEvent(input$check.fs, { ... }) , which would update reactives.

Any other ideas? Is there any way to do this only on the server without javascript?

shiny has a function called invalidatelater with wich you can invalidate a given reactive context. This makes it possible to reevaluate a function with a certain interval.

https://shiny.rstudio.com/reference/shiny/1.0.5/invalidateLater.html

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM