How to access OS environment variable from shiny app's server.R

I am getting blank when accessing OS environment variable USER from app's server.R installed on shiny server.
output$textoutput=renderText(paste("user name is ",Sys.getenv(c("USER"))))

The variable is available on bash prompt.
I tried exporting the variable as well.

Hi Jasmin, I was trying to recreate your request and it should work based on your mentioned code-snippet. :wink:

Best regards

P.S. Below is a short example: :slight_smile:


ui <- fluidPage(
  #display your 'textoutput'

server <- function(input, output, session){
  #get your user name based on 'Sys.getenv' (static object) <- paste0("user name is ",Sys.getenv(c("USER")))
  #test easy by printing on console
  #create UI output object 
  output$textoutput <- renderText({

shinyApp(ui, server)

1 Like

Thanks for confirming Adam, I will have to find why I am getting a blank

For security reason, a shiny that runs in a shiny server does not see all the environment variable of the system. It is like a sandbox process.

A discussion on this:

Sorry, this isn't possible today. We scrub most environment variables before launching R, in case there is sensitive information in them or .Renviron in you app is a way to pass environment variable, but it could not apply in your case.


This helps, thank you

This topic was automatically closed 54 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.