Skip to contents

This tutorial walks through the live stock-tracking dashboard in inst/examples/15-stock-tracker.R. It is designed to show how an rtui app can combine external data, dashboard layout, runtime chart drawing, timers, tables, logs, and keyboard shortcuts.

The app reads Yahoo Finance chart data through the public chart endpoint. That endpoint is useful for demos and prototypes, but it is not a formal market-data contract. For trading, compliance, or production monitoring, use a provider with documented terms, service guarantees, and retry/caching guidance.

What the app demonstrates

The dashboard uses:

Install requirements

The rtui runtime needs its Python Textual environment. The stock example also needs jsonlite to parse Yahoo Finance responses.

Run these setup commands from a normal R session, such as RStudio:

install.packages("jsonlite")
rtui::rtui_doctor()

If you are developing from this checkout after package-side changes, reinstall the local package once before launching the example in a separate terminal:

devtools::install_local(".", force = TRUE, upgrade = "never")

If rtui_doctor() reports missing Python dependencies, run:

Run from the project checkout

TUI apps must run from a real terminal, not the RStudio console or R GUI.

From PowerShell inside the rtui repo:

Rscript inst/examples/15-stock-tracker.R

On Windows, this assumes Rscript is on PATH. If PowerShell cannot find it, add R’s bin directory to PATH or reinstall R with command-line tools available. If Rscript itself shows a native application-error dialog before rtui loads, repair the R installation first; that is below rtui.

Run after installing rtui

When rtui is installed as a package, launch the packaged example with:

Rscript -e "source(system.file('examples', '15-stock-tracker.R', package = 'rtui'))"

Use the dashboard

Enter symbols as a comma-separated watchlist, for example:

AAPL, MSFT, NVDA, GOOGL, AMZN

Choose a range and interval, then press Refresh. The first symbol is the active chart symbol. The Watchlist tab fetches a compact quote snapshot for every symbol in the input.

To add one ticker without rewriting the whole list, type it into Add Symbol and press Add. The app appends it to the watchlist, loads that symbol, refreshes the table, and adds it to the Tracked Symbols list beside the chart.

To choose what the dashboard shows, open the Chart tab and select a ticker from Tracked Symbols. The Watchlist tab is the quote table; selecting a row there also makes that ticker active. Either selection path repopulates the KPI cards, chart, history table, sparklines, and status line from that symbol’s latest cached payload or a fresh Yahoo Finance request.

Keyboard shortcuts:

Key Action
r Refresh active quote and watchlist
1 Line chart
2 Candlestick chart
3 Volume chart
4 Close-vs-volume scatter plot
d Toggle dark mode
q or Escape Quit

Why the code is structured this way

The Yahoo request lives inside event and timer callbacks. That keeps package tests and source-time layout construction check-safe: sourcing the file builds the app, but it does not hit the network until the TUI is mounted.

Charts follow the rtui chart pattern:

box(text_plot(id = "price_chart"), border = "round")

on_mount = function(event, state) {
  plot_line(state$app, "price_chart", x = 1:10, y = runif(10))
  state
}

text_plot() is the layout widget. The plot_*() functions draw into that widget only after the Textual app is running.

Practical limits

This is a demo dashboard, not investment advice or a trading system. Yahoo Finance responses may be delayed, rate-limited, unavailable, or differ by market and symbol. The example logs errors in the Feed Log tab and keeps the UI running, but a production app should add:

  • Request caching and rate-limit backoff.
  • Provider-specific market-hours handling.
  • A stronger symbol search/validation workflow.
  • A formally supported data source for financial decisions.