Py.Cafe

maartenbreddels/

solara-great-tables

Interactive S&P 500 Visualization

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# inspired by https://py.cafe/jorge-santos/interactive-sp500-visualization
import solara
from great_tables import GT
from great_tables.data import sp500

# Define the start and end dates for the data range
start_date = "2010-06-07"
end_date = "2010-06-14"

@solara.component
def Page():


    # Filter sp500 using Pandas to dates between `start_date` and `end_date`
    sp500_mini = sp500[(sp500["date"] >= start_date) & (sp500["date"] <= end_date)]

    # Create a display table based on the `sp500_mini` table data
    display(
        GT(sp500_mini)
        .tab_header(title="S&P 500", subtitle=f"{start_date} to {end_date}")
        .fmt_currency(columns=["open", "high", "low", "close"])
        .fmt_date(columns="date", date_style="wd_m_day_year")
        .fmt_number(columns="volume", compact=True)
        .cols_hide(columns="adj_close")
    )
requirements.txt
1
2
3
solara
great_tables
pandas