Setting environment variable accessible to all scripts in the workspace

I am trying to create an app using R and shiny on posit cloud.

I noticed that when I set environment variables through the console with Sys.setenv(), they are set properly and when I run the app from the Rstudio interface, the app has access to these environment variables.
However, when I publish this app (onto posit cloud), even though it is still in the same workspace, the published shiny app no longer has access to them.

Is there a way to set environment variables that are accessible throughout the workspace?

Alternatively, is there a way to set environment variables accessible to published shiny apps?

Thank you!

Hi @OrangeO2,

The variables set in the console do not get transferred over when you publish. When you publish from the IDE it creates a bundle with all the necessary files for the shiny app and only code inside the bundle is then executed. I haven't done this myself, but I believe the way you get your shiny app to set environment variables is through the use of either the .Rprofile or .Renviron file. See this support article for better information on the process.

In regards to setting environment variables that are accessible throughout the workspace, we currently do not have that functionality in posit.cloud. We have the ability to store database connections that are accessible for all projects in a space, but nothing for general environment variables. It is on the roadmap to do at some point, but sadly I have no idea when we might actually get to it.

I hope the .Rprofile or .Renviron solution works for you though!

-Kyle

1 Like

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.