Site icon R-bloggers

Tutorial for Developing an Advanced Stock Dashboard for the S&P 500 for the 2025 Posit Table Contest

[This article was first published on Ozancan Ozdemir, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This tutorial breaks down the development of an R Shiny application titled S&P 500 Monitoring Dashboard for the 2025 Posit Table Dashboard. This app effectively combines interactive financial data visualization (plotly), beautiful data tables (gt, gtExtras), web scraping (rvest), and external API integration (riingo, ellmer/Gemini AI) within a custom, sleek dark theme. You can access the app through this link

1. Project Overview and Key Technologies

This application is divided into several functional panels:

  1. Market Overview: Top 10 S&P 500 companies by market cap, presented in a gt table with sparkline trends.
  2. Stock Details: Interactive selection, real-time price header, key statistics, and a daily/comparison price chart (plotly).
  3. Fundamental Analysis: Sortable table of key fundamental metrics.
  4. Market News & AI: News headlines (riingo) with sentiment analysis (sentimentr) and a large language model assistant (ellmer/Gemini AI).
  5. Portfolio Calculator: Simple portfolio backtesting and metric calculation.

📚 Core R Packages Used

Category Packages Purpose
App & UI shiny, htmltools, shinyLP Application framework, custom HTML/CSS theming.
Data Fetching quantmod, rvest, xml2, riingo Fetching stock data (Yahoo), web scraping (S\&P 500, fundamentals), and news (Tiingo).
Data Viz/Tables gt, gtExtras, plotly, svglite Creating highly styled, professional data tables and interactive charts.
AI Integration ellmer, shinychat Connecting to the Gemini API for the financial assistant.
Utilities dplyr, stringr, lubridate, zoo Data cleaning, manipulation, and time series handling.

2. Setting up the Environment and Helper Functions

The application starts by loading all necessary libraries and defining utility functions.

2.1. Icon and Theming Setup

The ICON_MAP list defines custom -awesome icons used in the statistics boxes, setting the inline CSS style for specific colors.

2.2. Web Scraping: get_sp500_tickers()

This crucial helper function scrapes the S&P 500 ticker list from Wikipedia.

2.3. Data Retrieval and Sparklines


3. The Custom Dark UI (ui.R)

The dashboard’s premium look is achieved entirely through custom CSS within the tags$head section of the ui.

3.1. Custom CSS Theme

The CSS (embedded using tags$style(HTML(...))):

3.2. Layout Structure

The fluidPage uses a simple three-column layout within the main-container (which is a custom-styled div):


4. The Server Logic (server.R)

The server manages data retrieval, reactive computations, and rendering of all outputs.

4.1. Stock Data Reactives

4.2. Dynamic Header & Stats

4.3. Advanced GT Table Rendering

The dashboard uses three major gt tables, each with heavy customization:

A. Key Stats Table (output$key_stats_table)

This table shows Market Cap, Revenue, and a 30-day price trend for the top stocks.

B. Daily Prices Table (output$price_table1)

This table shows the last 5 days of OHLC (Open, High, Low, Close) and key technical indicators (RSI, MACD).

C. Riingo News Table (output$riingo_news_gt)

This table displays news headlines based on the selected ticker and source.

4.4. Interactive Plotting (output$price_plot)

4.5. Portfolio Backtesting

The Portfolio Calculator section implements classic financial backtesting logic:

4.6. AI Chat Integration

To leave a comment for the author, please follow the link and comment on their blog: Ozancan Ozdemir.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version