Is there a way to create a streamlit app thats the same for everyone? More in description


I’m trying to create a streamlit app that is the same for every user. What do I mean by this? This wont be interactive and shown data shouldnt change depending on the user. As shown in the code snippet, I open a WebSocket Client to receive data from another script I have, this data will be plotted using different streamlit functions so that the user can visualize.
The problem starts when you open the site twice, this is a problem because streamlit tries to open another websocket with the same port. For what is worth, I’m trying to create a streamlit app that updates every time it received more data in the websocket.

Steps to reproduce

Code snippet:

socket_ran = False

# Setup the WebSocket
async def websocket_client(websocket, path):
    async for message in websocket:

async def server_handler():
    async with websockets.serve(websocket_client, "", 5255) as server:
        await asyncio.Future()
def run_server():
    if not socket_ran:
        print("Called Again")

ws_thread = threading.Thread(target = run_server)     

def _setup(name, ticker, date, status, variables):
    # Strategy Name
    # Ticker = ticker["name"]
    st.session_state.ticker.timeframe = ticker["timeframe"] = ticker["exchange"]

    # Strategy Date = date["from"] = date["to"]
    # Process Status
    st.session_state.status = status
    # Variables List
    st.session_state.variables = variables
    #? Example : Type : Setup
        "name":"Luda Kelt",
            "timeframe": "30m",
            "exchange": "ByBit"
        "variables": [

def _info(progress, status, eta, data):
    # Progress %
    st.session_state.progress = progrss
    # Status
    st.session_state.status = status
    # Estimated Time
    st.session_state.eta = eta
    # Combination Data = data
    #? Example : Type : Data
        "eta":"3 hours 22 minutes",
        "data": {

def on_message(message):
    if message["type"] == "setup":
            name = message["name"], 
            ticker = message["ticker"],
            date = message["date"],
            status = message["status"],
            variables = message["variables"]
    elif message["type"] == "data":
            progress = message["progress"],  
            status = message["status"],
            eta = message["eta"],
            data = message["data"]

def page_setup():
    # Page config
        page_title = "Testing", 
        layout = "wide", 
        initial_sidebar_state = "expanded"

Expected behavior:
Only one WebSocket should open, and every time new data is received in the websocket, those st.session_state attributes update, so that in future code, new data is shown to the user every time the websocket receives new data (hope this makes sense)

Actual behavior:
Two WebSocket Clients are being opened, and since you cant open a single port more than once, this raises an error.

Debug info

  • Streamlit version: 1.2
  • Python version: 3.10
  • OS version: Windows 10
  • Browser version: Chrome

Requirements file


Additional information

Please feel free to ask for more information, I’ll kindly provide it. Thanks in advance for your help.

what can I do for someone to help >7

I am not sure what you expect, you said.

Of course you have to take care of that. You need to figure out a way to tell whether you need to open the socket or it is already open and you can reuse it. cache_resource can help with that and you can also maintain app-global state in a module that your main script imports (modules are imported only once).

Your code is too async and websocky for my skillset so I cannot be more specific.