Hi Streamlit Community,
I have a query, I have 100 items in a st.selectbox. my requirement is whenever i select something from the list in st.selectbox and clicking a button should open a new browser tab with only that element which we selected from the st.selectbox.
Is it possible to done this Dynamically without using any other .py files? or i will have to use 100 separate .py files?
I want to use each element in different sessions since we need to do independent operations
from streamlit import session_state as ss
st.selectbox('Select', options=['Manila', 'Tokyo', 'Beijing'], key='country')
# Hitting the button redirects to a new session on same app under the pages folder.
st.link_button(
url=f'./processor/?country={ss.country}',
label=f'Hit me to start processing {ss.country}.'
)
pages/processor.py
import streamlit as st
# http://localhost:8501/processor/?country=Manila
qp = st.query_params
if qp:
st.json(qp.to_dict())
st.write(f'Processing {qp["country"]} ...')
I would connect the st.query_params with st.link_button, something like this:
But I think that would not conserve the session information between tabs?
import streamlit as st
list_options = ["Pear", "Banana", "Guanabana"]
fruit = st.query_params.get("fruit", None)
if fruit:
f"## {fruit} is a great choice! "
st.image(f"https://placehold.co/200x100?text={fruit}", caption=f"{fruit}!")
else:
selection = st.selectbox("Select:", list_options, index=None)
if selection:
st.link_button(
"See more!",
url=f"http://localhost:8501/?fruit={selection}",
use_container_width=True
)
Hi @ferdy ,
Thank you for the reply. So if there are 100 options, i only need to create 1 pages/processor.py?
All the pages that will be created should work independently.
I did not understand what you meant by this. As per the requirement i really don’t need session information between tabs, since every tab will be working independently.
Thanks @ferdy,
Actually I want to use Paramiko to connect to different servers and do some independent tasks. For the database race conditions, there will be individual databases for different servers. I think the race condition issue will not be a problem in this situation