I 'd like to add a link , which when user clicks opens a new window with pre-generated text. Is it possible to achieve with streamlit? Thank you
Hi @text2sql
Yes certainly. You can use an st.button()
and upon clicked, have it display the desired text.
import streamlit as st
button = st.button('Run')
if button:
st.write('This is the pre-generated text!')
thanks but it does not open a new tab/window. just shows the text.
Something like this using webbrowser and experimental_query_params would work.
import streamlit as st
import webbrowser as wb
page_params = st.experimental_get_query_params()
if page_params:
text = page_params.get("text")[0]
st.write(text)
else:
text = st.text_input("Enter Text")
btn = st.button("Click to open")
if btn:
wb.open_new_tab(f"http://localhost:8501/?text={text}")
st.info("Check new tab!")
Cheers
Thank you but it does not open a new tab. https://linkexperiments.legaltextai.repl.co/
import streamlit as st
import webbrowser as wb
page_params = st.experimental_get_query_params()
if page_params:
text = page_params.get(“text”)[0]
st.write(text)
else:
text = st.text_input(“Enter Text”)
btn = st.button(“Click to open”)
if btn:
wb.open_new_tab(
f"Streamlit")
st.info(“Check new tab!”)
Do you get any errors? Worked on my side. Also noticed you are not forming the query parameters in the right format.
it does generate the page with text but it does not open it
If you see my example, you need to provide an URL with the query parameters. Streamlit is not an URL.
wb.open_new_tab(f"http://localhost:8501/?text={text}")
this approach worked st.markdown(streamlitlink/?text={text}"
)
thanks so much for your help and your time
link button will be natively supported soon https://roadmap.streamlit.app/!
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.