Where should I load up-to-date data required for ui and server in a golem shiny app?

295 Views Asked by At

I have a golem app that loads data from an open government data portal. I need to access the data both in the ui (to make the choices fit the data) and in the server (to make a table and a plot), and I need the data to be up-to-date. Because I want the latest data, I do not load it as raw data and package it with the app. If this were not golem, I would probably load it at the top of the app.R file, thereby making it available both for the ui and the server. I ended up running the data-loading function in the file of the data-loading function, which seems like a bit of a hack. I found other golem apps (e.g. this one) that load the data in the server, where it would be up-to-date but not available to the ui. Where would you recommend to load data - within the golem framework - in a way that it is more or less up to date and available for both the ui and the server?

1

There are 1 best solutions below

0
On

I ran into the same issue attempting to use tidymodules and the developers offered this solution:

To do what you cant to do with R6, you can use the @include roxygen skeleton, that will generate a Collate entry in the DESCRIPTION file, and R will load the file in a specific order. Please see https://roxygen2.r-lib.org/reference/update_collate.html.

Another approach would be to define your R6 class as data object: https://r-pkgs.org/data.html