I've dashboard built using R Shiny. I use global.R, ui.R and server.R files. I've found this link How to trigger a data refresh in shiny? that suggests using invalidateLater
. But I use my global.R file to get the data from a cloud MySQL database, perform necessary data wrangling in the same global.R file. Could someone please let me know how to schedule a daily data refresh.
Asked
Active
Viewed 344 times
0

Karthik S
- 11,348
- 2
- 11
- 25
-
The data update needs to be done using reactives in `server.R`. You could use [reactivePoll](https://shiny.rstudio.com/reference/shiny/latest/reactivePoll.html) for this – Waldi Dec 13 '20 at 14:30
-
@Waldi, so there'd be no use of global.R ? I have multiple plots and data tables, for each plot, I need to get the data once then? – Karthik S Dec 13 '20 at 14:53
-
`global.R`is for static configuration data. `reactives` in `server.R` will allow to update data dynamically. – Waldi Dec 13 '20 at 16:35
-
@Waldi, could you please tell if there's a difference between invalidateLater and reactivePoll? – Karthik S Dec 13 '20 at 16:43
-
1The principle is similar, see [15.4.1 Polling](https://mastering-shiny.org/reactivity-objects.html) – Waldi Dec 13 '20 at 16:49
-
@Waldi, I asked another question regarding date-time. https://stackoverflow.com/questions/65286092/r-shiny-daterange-shows-non-existent-date-in-data. Could you please have a look – Karthik S Dec 14 '20 at 11:34
-
@Waldi, after running the App, the datetimes as in UTC, after deployment it's again back to IST (my time). But the issue of having an extra date even though that date is not there in the date still persists. – Karthik S Dec 14 '20 at 11:36
-
You could perhaps have a look at `lubridate::with_tz`and `lubridate::force_tz` to manage timezone as you wish – Waldi Dec 14 '20 at 13:42
-
@Waldi, one query, I just read that in order to use reactivePoll, the dashboard can't be idle. I just need to refresh data only twice a day. Will cronjob be a better option in that case? – Karthik S Jan 01 '21 at 11:52
-
cronjob is an useful option for a twice a day refresh. You could schedule an Rscript to update a data file (.rds for example) and read this data file in `server.R`. This is actually what I usually do. – Waldi Jan 01 '21 at 12:16
-
@Waldi, can't thank enough for the help Waldi. Will look up the solution you use. – Karthik S Jan 01 '21 at 12:50
-
1The following link might help : https://stackoverflow.com/questions/62319407/raspbian-linux-how-can-i-run-my-r-scripts-as-crontabs/62320335#62320335 – Waldi Jan 01 '21 at 13:57