Skip to content

Commit

Permalink
fix nba app (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinxu9 authored Apr 19, 2024
1 parent 4340a95 commit 895b15b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
8 changes: 6 additions & 2 deletions nba/nba/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import reflex as rx


def navbar():
return rx.box(
rx.hstack(
Expand All @@ -9,10 +10,13 @@ def navbar():
rx.flex(
rx.badge("2015-2016 Season"),
),
align="center",
),
rx.menu.root(
rx.menu.trigger(
rx.button("Menu", color="white", size="3", radius="medium", px=4, py=2),
rx.button(
"Menu", color="white", size="3", radius="medium", px=4, py=2
),
),
rx.menu.content(
rx.menu.item("Graph"),
Expand All @@ -37,4 +41,4 @@ def navbar():
width="100%",
top="0px",
z_index="500",
)
)
44 changes: 33 additions & 11 deletions nba/nba/nba.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Welcome to Reflex! This file outlines the steps to create a basic app."""

import reflex as rx
import pandas as pd
import plotly.express as px
Expand All @@ -8,15 +9,15 @@

nba_overview = "https://media.geeksforgeeks.org/wp-content/uploads/nba.csv"
nba_data = pd.read_csv(nba_overview)
college = sorted(nba_data["College"].unique().astype(str))
college = ["All"] + sorted(nba_data["College"].unique().astype(str))


class State(rx.State):
"""The app state."""

# Filters to apply to the data.
position: str
college: str
position: str = "All"
college: str = "All"
age: tuple[int, int] = (18, 50)
salary: tuple[int, int] = (0, 25000000)

Expand Down Expand Up @@ -79,15 +80,19 @@ def selection():
rx.hstack(
rx.vstack(
rx.select(
["C", "PF", "SF", "PG", "SG"],
placeholder="Select a position. (All)",
["All", "C", "PF", "SF", "PG", "SG"],
placeholder="Select a position.",
default="All",
on_change=State.set_position,
width="15em",
size="3",
),
rx.select(
college,
placeholder="Select a college. (All)",
placeholder="Select a college.",
default="All",
on_change=State.set_college,
width="15em",
size="3",
),
),
Expand All @@ -98,7 +103,12 @@ def selection():
rx.divider(orientation="vertical"),
rx.badge("Max Age: ", State.age[1]),
),
rx.slider(default_value=[18, 50], min=18, max=50, on_value_commit=State.set_age,),
rx.slider(
default_value=[18, 50],
min=18,
max=50,
on_value_commit=State.set_age,
),
align_items="left",
width="100%",
),
Expand All @@ -109,14 +119,18 @@ def selection():
rx.badge("Max Sal: ", State.salary[1] // 1000000, "M"),
),
rx.slider(
default_value=[0, 25000000], min=0, max=25000000, on_value_commit=State.set_salary,
default_value=[0, 25000000],
min=0,
max=25000000,
on_value_commit=State.set_salary,
),
align_items="left",
width="100%",
),
),
spacing="4",
),
align="center",
width="100%",
)

Expand All @@ -138,12 +152,20 @@ def index():
resizable=True,
),
rx.divider(width="100%"),
align="center",
padding_top="6em",
width="100%",
)
)



app = rx.App(theme=theme(appearance="light", has_background=True, radius="large", accent_color="amber", gray_color="sand",))
app.add_page(index, title="NBA App")
app = rx.App(
theme=theme(
appearance="light",
has_background=True,
radius="large",
accent_color="blue",
gray_color="sand",
)
)
app.add_page(index, title="NBA App")
7 changes: 4 additions & 3 deletions nba/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
reflex>=0.4.0
pandas>=2.2.0
plotly>=5.18.0
reflex>=0.4.8
pandas
plotly
statsmodels

0 comments on commit 895b15b

Please sign in to comment.