How to customize shiny based on which user is logged in

Hi,

I want to display different UI components based on which user is logged in.
The shiny app will have some UI components common to all users, but also have some other UI components that display user-specific data. Thus, whenever a user logs into the app, I need to know the user ID and customize the UI.

I looked at the session$clientData, but this doesn't seem to have the userID.

In shiny Python, is there a way to obtain the ID of the user who logged in

2 Likes

I asked this question to Shiny Assitant.

It suggested a workaround:

  • Create a shiny with login page and multiple conditional UIs
  • First only login page will be visible. The user logs in with his credentials. There will be a locally stored dictionary of User ID and Passwords. The login credentials are checked against this dictionary
  • If the user ID and password are valid, then we will display a conditional UI based on which user is logged in

This method works as expected. But you need to supply the dictionary of IDs and passwords (which is not so safe) and you cannot use google authentication.

Are there any other methods to solve this problem?

In Shiny for Python, user authentication isn't built-in, so you’ll need an external auth system (e.g., OAuth, Firebase, or a custom login module). If using Shiny Server Pro or Connect, you can access session.env['SHINYPROXY_USER'] or similar. Otherwise, handle login manually and store the user ID in session.user_data, then conditionally render UI components based on it. :rocket:

Thanks for the clarification.
Then the method suggested by ShinyAssistant seems to be a good candidate to solve this.

1 Like