Create And Deploy A Stock Price Web Application using Python and Streamlit
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
Create A Stock Price Web Application Using Streamlit
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.
Command to run your code
streamlit run myapp.py
Deploy Data Science Web App Using Streamlit
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: