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
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.