Test if my R shiny code is running in an RStudio Connect server


I have a shiny code that runs on an RStudio Connect server. Due to the size of datasets that it is means to upload these dataset files are saved on the cloud and only upon selection of the user that's using the deployed shiny app on the RStudio Connect server, the selected dataset's files are copied from the cloud to the RStudio Connect server directory, read by the shiny code, and subsequently deleted.

I would like to allow this shiny code to also be run locally (meaning not on the RStudio Connect server). So ideally I'd have a condition in the code to test if it is on the RStudio Connect server or locally. In case of the former, proceed with the procedure I described above and in case of the latter, read the selected dataset's files locally (they are assumed to exist there).

Is there such an R function/command that tests if the code is executed on the RStudio Connect server or locally? Or this cannot be done and I need to resort to having two R shiny codes, one for the RStudio Connect server and the other for the local usage?


It sounds like the {config} package might be good for your use case. See an example use here: https://kellobri.github.io/shiny-prod-book/connecting-to-data-in-production.html#the-config-package

by default, the environment variable R_CONFIG_ACTIVE will be set to "rsconnect" when your app is running on Connect.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.