Create And Deploy A Stock Price Web Application using Python and Streamlit

12 Nov, 2021
In this article, we are going to see how to create and deploy a stock price web application.
To create an amazing Web Application that deals with Data Science, we have a perfect platform to carry out this task. Streamlit and Python package builds and shares the data application in the fastest way possible. 
Streamlit is open source anyone can contribute to it but first install Streamlit locally.
pip install streamlit
Streamlit ensures the fastest way to build and share data apps. Stock is always going to be the trending matter for years to speak. Everyone with a good income likes to invest in the Stock market. A Stock Market is a place where shares of pubic listed companies are traded. Since we are dealing with Stock Price details, we might require Web Scrap the details. But to our recuse, there is one such Python library that deals with the stock price. Yahoo Finance in short finance works with online advertising companies to provide you with advertising that is as relevant and useful as possible.
pip install yfinance
First import the necessary modules required for the Web Application.
import streamlit as st
import yfinance as finance
You need to know the basic syntax of Markdown to display text on Web App. You can check this Introduction to Markdown and get started. Once you get familiar with Markdown language displaying messages using Streamlit becomes an easy task.
Set the title name, sidebar header, and Subheading:
st.title("Build and Deploy Stock Market App Using Streamlit")
st.header("A Basic Data Science Web Application")
st.sidebar.header("Geeksforgeeks \n TrueGeeks")
The actual part of the code begins now. Since we will be analyzing the  Google and Microsoft stock prices, initialize the ticker attribute, and get the history of GOOGL and MSFT for the past one month. 
yfinance allows you to check the updates over a certain period of time. yfinance returns pandas.DataFrame with multi-level column names, with a level for the ticker and a level for the stock price data. You can check the below code that displays the heading, data, summary information about the company, and plot an amazing graph.
yfinace.download displays tabular data that includes Open, High, Low, Closing, and Volume data at different time intervals. Once you have initialized the ticker you check the detailed information about the ticker that includes the long summary, the total number of employees, the state and country name, the revenue growth, and much more information. 
We have used the most important commands for this web application you can check the below code.
Python
import streamlit as stimport yfinance as finance  def get_ticker(name):    company = finance.Ticker(name)  # google    return company  # Project Detailsst.title("Build and Deploy Stock Market App Using Streamlit")st.header("A Basic Data Science Web Application")st.sidebar.header("Geeksforgeeks \n TrueGeeks") company1 = get_ticker("GOOGL")company2 = get_ticker("MSFT") # fetches the data: Open, Close, High, Low and Volumegoogle = finance.download("GOOGL", start="2021-10-01", end="2021-10-01")microsoft = finance.download("MSFT", start="2021-10-01", end="2021-10-01") # Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,maxdata1 = company1.history(period="3mo")data2 = company2.history(period="3mo") # markdown syntaxst.write("""### Google""") # detailed summary on Googlest.write(company1.info['longBusinessSummary']) st.write(google) # plots the graphst.line_chart(data1.values)  st.write("""### Microsoft""")st.write(company2.info['longBusinessSummary'], "\n", microsoft)st.line_chart(data2.values)
 streamlit run myapp.py
Streamlit web applications can be deployed for direct use through various options available on the internet. There are different platforms on how you could deploy the Streamlit application. You can deploy your app using Heroku as well. Check the complete guide to deploy apps on Heroku.
We will be looking into a direct method provided by Streamlit itself. The free Community tier is the perfect solution if your app is hosted in a public GitHub repo and you’d like anyone in the world to be able to access it. Before proceeding further you will require your own GitHub account where you will save your Web app. Once you have put your app on GitHub make sure you have added a requirement.txt file. This file will contain the necessary Python library which is required. 
You need to follow just three-step to deploy your app:
Step 1: Create a Github Repository for your Streamlit app and then Sign-up (https://forms.streamlit.io/community-sign-up)to Streamlit Community. 
Step 2: You need to wait for 2 business days and then you can finally deploy your app. Open the mail which you will receive from the https://share.streamlit.io/ community and create a new app.
Step 3: Next select the repo which you created at the first step. After selecting repo_name, Choose the branch name and main python file where you have saved your code.
Once your app is deployed, you can find it with this URL:
https://share.streamlit.io/[username]/[repo_name]/[default_branch_name]/[your_py_code_file_name]
singghakshay
Python-streamlit
python-utility
TrueGeek-2021
Python
TrueGeek
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
How to redirect to another page in ReactJS ?
How to remove duplicate elements from JavaScript Array ?
How to Convert Char to String in Java?
Basics of API Testing Using Postman
Types of Internet Protocols