Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my Streamlit application open multiple times?

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?

like image 871
mime Avatar asked Nov 10 '19 10:11

mime


People also ask

What are the limitations of Streamlit?

Disadvantages of Streamlit Will not scale. Cannot easily customize any of the frontend components. Relatively new, so there are features that are still beta. Since it's relatively new, sometimes it's hard to find answers to your questions.

Is Streamlit a Python library?

Streamlit is an open-source Python library that makes it easy to create and share beautiful, custom web apps for machine learning and data science. In just a few minutes you can build and deploy powerful data apps. So let's get started!


1 Answers

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")
like image 197
nthmost Avatar answered Oct 11 '22 16:10

nthmost