Logged in user info in Shiny App

Hi,

I’m trying to figure out how to obtain the logged in user’s information inside my Shiny app since I want to implement some user specific features inside in the App rather than different apps for different users. I checked the session$clientData$url_search and found nothing.

A related question is, I want to not only customize the app’s logic according to the user’s profile but also to mount the user’s storage to the container so users can access their files. If I’m using NFS, it looks to me the only solution is to use -v to mount the storage when starting the docker container, if so, only being able to specify the mount point in the application.yml will not work in this case because it’s static and not user specific.

Thanks!

Found an environment variable “SHINYPROXY_USERNAME” that is passed into the Docker container. However Shiny hides most of the environment variables from the internal R process. I’m still investigating if I can run ‘env > env.txt’ in the docker container when it starts so the Shiny App can read this file for variable values.

When I run ‘system(‘env’)’ within a regular R session in the docker container, it will show the SHINYPROXY_USERNAME variable. However, when I use this command in the Shiny App and print it to verbatim output there is no this variable anymore.

Hi @Keqiang_Li,

This sounds like an interesting idea.
The application.yml may already contain references to environment variables, but they refer to the ShinyProxy’s process daemon, not the ShinyProxy logged-in user, so a setting like

docker-volumes: [ "${HOME}/path1:/container/path1" ]

does not make much sense for the user.

But maybe we can expand this to also inspect SHINYPROXY_USERNAME so that you can configure your app like this:

docker-volumes: [ "/host/mnt/${SHINYPROXY_USERNAME}/path1:/container/path1" ]

Would that help your case?
We could also include the variables listed in

docker-env-file: a path to a file in which environment variables are specified to be passed to the container

(https://www.shinyproxy.io/configuration/#apps)

Regards,
Frederick

Hi @fmichielssen,

Using docker-volumes: [ "/host/mnt/${SHINYPROXY_USERNAME}/path1:/container/path1" ] would definitely help, the only thing is if authentication is disabled, this might cause an error since I guess SHINYPROXY_USERNAME will be evaluated to null. If nicely implemented, this feature looks to me is very useful for user customized app. One thing I’m worried about is that the variables in the application.yml should be the host’s variables, letting SHINYPROXY_USERNAME be available here is a bit confusing since at the same time there might be a few users using shinyproxy.

I don’t quite get the docker-env-file solution because I don’t get a chance to generate an env file containing the logged in user name for each user and point to it in the application.yml file. Sounds more like the shinyproxy app itself should start the docker with some specified env variables or an env file.

Since Shiny apps are client-server applications, I think encoding some of the parameters in the URL will help as well. As said in my last reply, even the env variable is passed to the docker container, the Shiny App process still can’t access it(the container can). It’s like the Shiny Server modified the enviroment variables before launching each App. A suggested way from Shiny google group is to execute ‘env’ command after the container launches and write the results to a file and later refer to the file from within the Shiny App, but I keep failing to use CMD(or ENTRYPOINT) to achieve this in my dockerfile.

I managed to get the SHINYPROXY_USERNAME variable by invoking a script in the Dockerfile using CMD that contains this line env > /srv/shiny-server/envars.txt. This will cause the `env’ to be executed after the container starts. Then in the Shiny app, just read this file to get the variable(may need to change the file permission).

Just FYI, it seems that you are using shiny server in your container, and it hides the env variables.
When using ‘plain’ shiny as in the templates/examples, you will be able access to the “SHINYPROXY_USERNAME” variable without any extra steps.

Thank you very much for this information.

Actually, I have been wondering about how this ‘plain’ shiny is working without Shiny Server? Is Shinyproxy hosting the app on its web server instead?

Thanks!