From 895b15b8328c81bb336e8652d2449354f0ac5d26 Mon Sep 17 00:00:00 2001 From: Martin Xu <15661672+martinxu9@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:47:22 -0700 Subject: [PATCH] fix nba app (#225) --- nba/nba/helpers.py | 8 ++++++-- nba/nba/nba.py | 44 +++++++++++++++++++++++++++++++++----------- nba/requirements.txt | 7 ++++--- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/nba/nba/helpers.py b/nba/nba/helpers.py index 52e28858..7e7d7ba1 100644 --- a/nba/nba/helpers.py +++ b/nba/nba/helpers.py @@ -1,5 +1,6 @@ import reflex as rx + def navbar(): return rx.box( rx.hstack( @@ -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"), @@ -37,4 +41,4 @@ def navbar(): width="100%", top="0px", z_index="500", - ) \ No newline at end of file + ) diff --git a/nba/nba/nba.py b/nba/nba/nba.py index 78dcd3eb..2d65db06 100644 --- a/nba/nba/nba.py +++ b/nba/nba/nba.py @@ -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 @@ -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) @@ -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", ), ), @@ -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%", ), @@ -109,7 +119,10 @@ 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%", @@ -117,6 +130,7 @@ def selection(): ), spacing="4", ), + align="center", width="100%", ) @@ -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") \ No newline at end of file +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") diff --git a/nba/requirements.txt b/nba/requirements.txt index 9166e192..ea08ad37 100644 --- a/nba/requirements.txt +++ b/nba/requirements.txt @@ -1,3 +1,4 @@ -reflex>=0.4.0 -pandas>=2.2.0 -plotly>=5.18.0 +reflex>=0.4.8 +pandas +plotly +statsmodels