Hi!
I would like to develop an app that shows one chart that contains multiples stocks simoultaneously taken from yahoo finance. The flow should be the following:
-
Choose the stocks from checkboxes;
-
Press a button that load into a list each stock checked;
-
Download from yahoo finance the time series of the stock selected and print in one chart
My issues are that I don’t know how to convert into a list all the checkboxes ‘checked’ and how to do a button that trigger it and then download the data.
Hey @Mattia_Bolognesi,
Some tips to get you started :
- You can go from a list of checkboxes to list of checked stocks with some Python list manipulation. Example :
stocks = ["ST", "STR", "STREAM", "STREAMLIT"]
check_boxes = [st.sidebar.checkbox(stock, key=stock) for stock in stocks]
st.write([stock for stock, checked in zip(stocks, check_boxes) if checked])
- run some code after triggering a button
checked_stocks = [stock for stock, checked in zip(stocks, check_boxes) if checked]
if st.button("Download data"):
for stock in checked_stocks:
download_data(stock) # <-- download data with requests for example for this stock
I remember some posts regarding stock download you can check for inspiration notably Stocks views which has a link to source code, notably a function for downloading stock data with yfinance.
Fanilo
2 Likes
Superb, it helped me in my case thank you.