Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nba app radix #199

Merged
merged 9 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified chakra_apps/chatroom/assets/favicon.ico
Binary file not shown.
3 changes: 0 additions & 3 deletions chakra_apps/nba/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
# The way to run nba
pynecone==0.1.27 + The minimum version of node is 16.6.0.
If the node's version is smaller than 16.6.0, the code cannot run.
7 changes: 3 additions & 4 deletions chakra_apps/nba/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
reflex>=0.3.8
plotly-express
plotly
pandas
reflex>=0.4.0
pandas>=2.2.0
plotly>=5.18.0
4 changes: 1 addition & 3 deletions chakra_apps/nba/rxconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

config = rx.Config(
app_name="nba",
db_url="sqlite:///reflex.db",
env=rx.Env.DEV,
)
)
3 changes: 1 addition & 2 deletions clock_radix/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.db
*.py[cod]
.web
__pycache__/
reflex.db
__pycache__/
4 changes: 4 additions & 0 deletions nba/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.db
*.py[cod]
.web
__pycache__/
Binary file added nba/assets/favicon.ico
Binary file not shown.
Binary file added nba/assets/nba.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added nba/nba/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions nba/nba/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import reflex as rx

def navbar():
return rx.box(
rx.hstack(
rx.hstack(
rx.image(src="/nba.png", width="50px"),
rx.heading("NBA Data", size="8"),
rx.flex(
rx.badge("2015-2016 Season"),
),
),
rx.menu.root(
rx.menu.trigger(
rx.button("Menu", color="white", size="3", radius="medium", px=4, py=2),
),
rx.menu.content(
rx.menu.item("Graph"),
rx.menu.separator(),
rx.menu.item(
rx.link(
rx.hstack(rx.text("20Dataset"), rx.icon(tag="download")),
href="https://media.geeksforgeeks.org/wp-content/uploads/nba.csv",
),
),
),
),
justify="between",
border_bottom="0.2em solid #F0F0F0",
padding_inline_start="2em",
padding_inline_end="2em",
padding_top="1em",
padding_bottom="1em",
bg="rgba(255,255,255, 0.97)",
),
position="fixed",
width="100%",
top="0px",
z_index="500",
)
149 changes: 149 additions & 0 deletions nba/nba/nba.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
"""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
import plotly.graph_objects as go
from .helpers import navbar
from reflex.components.radix.themes import theme

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))


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

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

@rx.var
def df(self) -> pd.DataFrame:
"""The data."""
nba = nba_data[
(nba_data["Age"] > int(self.age[0]))
& (nba_data["Age"] < int(self.age[1]))
& (nba_data["Salary"] > int(self.salary[0]))
& (nba_data["Salary"] < int(self.salary[1]))
]

if self.college and self.college != "All":
nba = nba[nba["College"] == self.college]

if self.position and self.position != "All":
nba = nba[nba["Position"] == self.position]

if nba.empty:
return pd.DataFrame()
else:
return nba.fillna("")

@rx.var
def scat_fig(self) -> go.Figure:
"""The scatter figure."""
nba = self.df

if nba.empty:
return go.Figure()
else:
return px.scatter(
nba,
x="Age",
y="Salary",
title="NBA Age/Salary plot",
color=nba["Position"],
hover_data=["Name"],
symbol=nba["Position"],
trendline="lowess",
trendline_scope="overall",
)

@rx.var
def hist_fig(self) -> go.Figure:
"""The histogram figure."""
nba = self.df

if nba.empty:
return go.Figure()
else:
return px.histogram(
nba, x="Age", y="Salary", title="Age/Salary Distribution"
)


def selection():
return rx.vstack(
rx.hstack(
rx.vstack(
rx.select(
["C", "PF", "SF", "PG", "SG"],
placeholder="Select a position. (All)",
on_change=State.set_position,
size="3",
),
rx.select(
college,
placeholder="Select a college. (All)",
on_change=State.set_college,
size="3",
),
),
rx.vstack(
rx.vstack(
rx.hstack(
rx.badge("Min Age: ", State.age[0]),
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,),
align_items="left",
width="100%",
),
rx.vstack(
rx.hstack(
rx.badge("Min Sal: ", State.salary[0] // 1000000, "M"),
rx.divider(orientation="vertical"),
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,
),
align_items="left",
width="100%",
),
),
spacing="4",
),
width="100%",
)


def index():
"""The main view."""
return rx.center(
rx.vstack(
navbar(),
selection(),
rx.divider(width="100%"),
rx.plotly(data=State.scat_fig, layout={"width": "1000", "height": "600"}),
rx.plotly(data=State.hist_fig, layout={"width": "1000", "height": "600"}),
rx.data_table(
data=nba_data,
pagination=True,
search=True,
sort=True,
resizable=True,
),
rx.divider(width="100%"),
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")
3 changes: 3 additions & 0 deletions nba/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
reflex>=0.4.0
pandas>=2.2.0
plotly>=5.18.0
5 changes: 5 additions & 0 deletions nba/rxconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import reflex as rx

config = rx.Config(
app_name="nba",
)