Purpose and How It Works

The Stock Market Tracker App is a simple yet powerful tool that allows users to track the historical prices of their favorite stocks. By entering the symbols of the stocks they’re interested in, users can get a visual representation of the stocks’ performance over time. This can be useful for investors, financial analysts, or anyone interested in the stock market.

Using the app is straightforward. Simply enter the symbols of the stocks you want to track in the text box, separated by commas. For example, if you want to track Apple, Google, and Microsoft, you would enter ‘AAPL,GOOG,MSFT’.

Technical Details - Part 1

# Defines server logic for Stock Market Tracker App
server <- function(input, output) 
  output$stockPlot <- renderDygraph({
    # Split the input into individual symbols
    symbols <- strsplit(input$symbols, ",")[[1]]
    # Trim any leading/trailing white space
    symbols <- trimws(symbols)
    
    # Fetches the stock data
    data <- do.call(cbind, lapply(symbols, function(sym) {
      getSymbols(sym, src = "yahoo", auto.assign = FALSE)
    }))
    
    # Plots the data
    dygraph(data, main = "Historical Stock Prices")
  })

Technical Details - Part 2

The app is built using R Shiny, a framework for building interactive web apps using R. When you enter the stock symbols, the app uses the getSymbols function from the quantmod package to fetch the historical stock data from Yahoo Finance.The data is then plotted using the dygraph function from the dygraphs package. Shiny’s reactivity model ensures that the plot updates automatically whenever you enter new stock symbols.

Conclusion

The Stock Market Tracker App is a handy tool for anyone interested in tracking stock prices. Whether you’re an experienced investor or just starting to learn about the stock market, this app can provide valuable insights into the performance of your favorite stocks.