โ12-05-2024 10:21 PM
I have created a Databricks App using streamlit and able to deploy and use it successfully.
I need to get the user name/email address of the logged in user and display in the streamlit app. Is this possible?
If not possible at the moment, any roadmap for adding this feature?
regards,
--
satniks
โ12-06-2024 06:01 AM
Yes, it is possible to retrieve and display the username or email address of the logged-in user in a Streamlit app deployed on Databricks. This can be achieved through two primary approaches:
1. Using "st.experimental_user" in streamlit.
import streamlit as st
# Access the user's email
user_email = st.experimental_user.get("email", "Unknown User")
# Display the email in the app st.write(f"Logged in as: {user_email}")
2. Using HTTP Headers in Databricks Apps.
import os
import streamlit as st
# Access headers passed by Databricks Apps
user_email = os.getenv("X-Forwarded-Email", "Unknown User")
# Display the user's email
st.write(f"Logged in as: {user_email}")
Hope this helps. Cheers, Louis.
โ12-08-2024 04:53 PM
โ12-06-2024 06:01 AM
Yes, it is possible to retrieve and display the username or email address of the logged-in user in a Streamlit app deployed on Databricks. This can be achieved through two primary approaches:
1. Using "st.experimental_user" in streamlit.
import streamlit as st
# Access the user's email
user_email = st.experimental_user.get("email", "Unknown User")
# Display the email in the app st.write(f"Logged in as: {user_email}")
2. Using HTTP Headers in Databricks Apps.
import os
import streamlit as st
# Access headers passed by Databricks Apps
user_email = os.getenv("X-Forwarded-Email", "Unknown User")
# Display the user's email
st.write(f"Logged in as: {user_email}")
Hope this helps. Cheers, Louis.
โ12-08-2024 10:30 PM
X-Forwarded-Email worked. I assume you mean using st.context.headers.get() instead of os.getenv().
โ12-08-2024 04:53 PM
โ12-08-2024 10:25 PM
Thanks @BigRoux and @Shannon_O for your response.
I tried st.experimental_user.get() API but it gives me hardcoded response as test@example.com
Suggestion to use X-Forwarded-Email header worked and I got correct email address. Thanks for your help. I am unblocked now.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group