Why does my Streamlit application open multiple times?
Asked Answered
P

1

6

I am trying to start the Streamlit application using

import os
os.popen("streamlit run stockXchange.py")

When I run this code, there will be an infinite number of streamlit windows, popping up one after another every 3 or so seconds. The only way to stop these windows from popping up is by closing the output window completely. (I am using PyCharm)

Here is my code:

import os
import streamlit as st
class Streamlit:


    def __init__(self):
        Streamlit.setup()


    def setup(self):
        st.title("StockXchange GUI")
        query = st.text_input("Enter company name:")
        if st.button("Go"):
            #calls the application function
            load(query)



if __name__ == "__main__":
    print(starttext)
    print(os.popen("streamlit run stockXchange.py").read())
    #Workaround 'missing 1 required positional argument: 'self'' Error
    Streamlit.setup(Streamlit)

I want there to only be one window popping up, not an infinite number of windows.

Is there any way to fix this?

Pediatrics answered 10/11, 2019 at 10:6 Comment(0)
J
4

With Streamlit you don't need to create a class wrapper to run your Streamlit application.

Presuming that your stockXchange.py is the streamlit app, then it should be run from the command line or from the PyCharm console like so:

streamlit run stockXchange.py

All of the following lines from your class should go into that file:

st.title("StockXchange GUI")
query = st.text_input("Enter company name:")
if st.button("Go"):
    #the rest of stockXchange.py pertaining to the query

The reason you're getting unlimited streamlit windows is that the following line creates an infinite loop in terms of program execution:

if __name__ == "__main__":
    os.popen("streamlit run stockXchange.py")
Jordain answered 13/11, 2019 at 1:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.