st.link_button to open in same tab
Checklist
- [X] I have searched the existing issues for similar feature requests.
- [X] I added a descriptive title and summary to this issue.
Summary
The recently launched st.link_button opens up in a new tab. But if I want to use session states, they reset out if the redirection happens in different tab. I hope there should be an argument input which can decide whether to open the redirection in same tab or new tab.
Let's say I have multiple headers in multi page apps, I want the user to redirect to a particular link to read more on that, I want the link button to redirect in the same page irrespective of the number of multi pages and this should also preserve the session states.
Why?
I am working on a streamlit app which shows multiple URLs but instead of that the st.link_button can make it look more appealing. But the problem is that the app works with session states and if the user clicks the button, the page opens up in new tab which resets the session states. I want to open the redirection links in the same state so that the I use it with my existing session states.
This kind of also helps to log whether the user has pressed the redirect button or not.
Let's say there is a lot of data or text over a topic and scattered randomly but I want to include a redirect button in the same page but St link button works fine in that case but it resets the session states since it opens in new tab.
How?
st.link_button should take an optional argument called new_tab which is Boolean. If new_tab is False then if the user clicks the button it should jump to that link without disturbing the session states.
If new_tab is set true then it can open the link in new tab with new session states.
Additional Context
No response
To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.
Your vote helps us identify which enhancements matter most to our users.
Hey @LukasMasuch @Harisathwik , I would like to work on this feature.
Hey, thanks for the request.
It currently opens in a new tab because opening links in the same tab often doesn't work properly due to the iframe boundary we have around the app on Streamlit Community Cloud (and in many other deployments). That's why all links in Streamlit (no matter if just a normal markdown link or st.link_button) open in a new tab by default.
We are aware of the request to switch pages in a multipage app while preserving session state and will implement that at some point. Note that simply making a link open in the same tab will not solve that, since clicking on a link reloads the entire web page and resets session state regardless of if it opens in a new tab or not.
My 5 cents. I need a way to log out from SSO. Had to use markdown with target="_self" instead of the link_button (same tab, goes to SSO, logs out user session there, immediately reroutes back to streamlit - logged out already, all in the same page). I'd really like to use the button there, but currently that means opening new tab with the same process, leaving old page hanging at where it was, so 2x tabs and old tab at wrong place.
This seems to be related to #6922 .
My 5 cents. I need a way to log out from SSO. Had to use markdown with
target="_self"instead of the link_button (same tab, goes to SSO, logs out user session there, immediately reroutes back to streamlit - logged out already, all in the same page). I'd really like to use the button there, but currently that means opening new tab with the same process, leaving old page hanging at where it was, so 2x tabs and old tab at wrong place.
This inspired a working solution st.markdown('<a href="/?key=value" target="_self">View all</a>',unsafe_allow_html=True)
This inspired a working solution
st.markdown('<a href="/?key=value" target="_self">View all</a>',unsafe_allow_html=True)
yep, that's exactly what I'm using. Would still prefer a pythonic button with proper options.
Hi. The issue is still ongoing. Are there any plans to implement this feature?
This would be a helpful option to enable users of Auth0 to completely Logout using https://auth0.com/docs/authenticate/login/logout/redirect-users-after-logout