Hi,
I have a multi-page app setup.
I run my main.py with “–client.showSidebarNavigation=False” so that by default the sidebar is not visible.
The contents of my sidebar will be based on the login credential.
Once the user logs in, I do a “switch_page” to say “pages/admin_view.py”.
In this page, I render a logout button (my own st.button)
And then create new links in the sidebar using “st.page_link”
In each such new page whose link is now in the side-bar, I render the “logout” button when it is run (i.e when clicked) and also render the same page-links related to “admin”. Thus the side-bar contents remain the same when I switch between these pages.
ISSUE:
The first time I switch to one of the pages created using “st.page_link”, I encounter duplicate key issue with my st.button that I use to implement “logout”
But from the next click onwards, its all well set and no issue arises.
Its only for the first time, I encounter this weird issue.
I am using streamlit 1.31.
I also tried with 1.32 and the problem is the same.
I think this is a bug… Anyone else has witnessed such an issue?
The sidebar drawing function is in admin_view.py and renders a logout button at the end after rending the different page_links pertaining to the admin role.
In admin_tasks, I import like this → “from pages.admin_view import admin_sidebar”, and then invoke the function.
When doing so, the very first time when you click “admin_view” link in the app, you encounter this issue of duplicate widget and after that no issue is seen,
If I replicate the admin_sidebar function in admin_view.py, there is no issue at all.
Hope this helps.
I have a repro case. How do I upload this?
–EDIT–
Never mind, I just added a post below with repro. Hope that works for you. Thanks!
UPDATE: I re-tested it again today and I see that when I move the admin_sidebar() to a separate file, it just works fine. I must have missed something. Please ignore this post
btw… The error persisted even when I moved the “admin_sidebar()” function to a separate file called admin_utils.py
When I moved the logout button to the actual file (admin_tasks.py), everything worked well…
@ferdy The repro case is above the post. The workaround is in this post. Hope this suffices. Thanks!
@ferdy Thanks for testing and for your suggestion. I had already tried your suggestion and updated in a post above. That did not work too… The “st.button” call needs to be in the admin_xxx file. The page_links can be outside in a module… You can verify this too. Thanks again!
Oops… you are right. I re-tested it again and your suggestion works just fine. I must have been mistaken yesterday.
Let me post a errata in my prev post.
Thanks for your time!