Is there a way to access st.tabs based on user role

To handle PDFs across folders, I wrote some code. Implementing user role-based access control is what I desire. Two tabs utilizing st.tabs (tab1, tab2) are used in my user interface.

I would like to make a guest account that can only visit tab 2 and an admin account that can access both tabs. Is it possible to accomplish this in streamlit st.tabs?

if role == "admin":
    admin_tab, guest_tab = st.tabs(["Admin", "Guest"])
    with admin_tab:
        ...
    with guest_tab:
        ...
elif role == "guest":
    guest_tab, = st.tabs(["Guest"])
    with guest_tab:
        ...
2 Likes
if role == "admin":
    admin_tab, guest_tab = st.tabs(["Admin", "Guest"])
    with admin_tab:
        ...
    with guest_tab:
        ...
elif role == "guest":
    guest_tab, = st.tabs(["Guest"])
    with guest_tab:
        ...

One thing I observed is to put a comma after guest tab, ensures that the variable guest_tab is correctly assigned when the function st.tabs(["Guest"]) returns a tuple.
1 Like

Thanks! Corrected the oversight

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.