How to open new browser tab dynamically without different pages

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.

  1. Is it possible to done this Dynamically without using any other .py files? or i will have to use 100 separate .py files?
  2. I want to use each element in different sessions since we need to do independent operations

Any suggestions or pointers will be appreciated.

Thanks in advance.

A perfect timing to showcase both query_params and link_button.

  • I will use another file under the pages folder.
  • It will open a new tab as different session.

app.py

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:

lint_to_query_from_selectbox

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.

Thanks a lot for the answer!

Hi @edsaac,

Thanks a lot for the answer.

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.

Can you give me some insights regarding this.

Thanks a lot for the reply!

They will not share session states.

You have to be careful though if processor.py is accessing a database for example. Reading is fine, but writing is an issue because of race condition.

It would be better if you tell us what process are you going to do.

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

Ah, got it, i understood you needed the opposite. It should work fine then!

Hi @edsaac, Thanks a lot for confirming.

Thanks a lot @ferdy and @edsaac for the help