Upload 5 files
Browse files- app.py +6 -0
- cencus.csv +21 -0
- requirements.txt +4 -0
- server.py +46 -0
- ui.py +43 -0
app.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from shiny import App
|
2 |
+
from ui import create_ui
|
3 |
+
from server import create_server
|
4 |
+
|
5 |
+
# Create the Shiny app
|
6 |
+
app = App(create_ui(), create_server())
|
cencus.csv
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
id,name,sex,country
|
2 |
+
1,Georgie,M,France
|
3 |
+
2,Ware,M,Tajikistan
|
4 |
+
3,Kenton,M,Russia
|
5 |
+
4,Claresta,F,Philippines
|
6 |
+
5,Barrett,M,Yemen
|
7 |
+
6,Dennie,F,China
|
8 |
+
7,Clyve,M,Ivory Coast
|
9 |
+
8,Arvy,M,Japan
|
10 |
+
9,Erek,M,Indonesia
|
11 |
+
10,Morena,F,Brazil
|
12 |
+
11,Darb,M,Russia
|
13 |
+
12,Rubi,F,Croatia
|
14 |
+
13,Clarinda,F,Philippines
|
15 |
+
14,Celesta,F,Philippines
|
16 |
+
15,Albertine,F,Cuba
|
17 |
+
16,Cleavland,M,China
|
18 |
+
17,Edward,M,Sweden
|
19 |
+
18,Kittie,F,Ethiopia
|
20 |
+
19,Rene,F,China
|
21 |
+
20,Jonell,F,Dominica
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
shiny==0.6.0
|
2 |
+
pandas==2.1.0
|
3 |
+
matplotlib==3.8.0
|
4 |
+
jinja2==3.1.2
|
server.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from shiny import render, reactive, ui
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
def create_server():
|
6 |
+
def server(input, output, session):
|
7 |
+
# Update dropdowns when file is uploaded
|
8 |
+
@reactive.Effect
|
9 |
+
def _():
|
10 |
+
file = input.file()
|
11 |
+
if file is not None:
|
12 |
+
# Read the uploaded file
|
13 |
+
df = pd.read_csv(file[0]['datapath'])
|
14 |
+
choices = list(df.columns)
|
15 |
+
ui.update_select("var1", choices=choices, session=session)
|
16 |
+
ui.update_select("var2", choices=choices, session=session)
|
17 |
+
|
18 |
+
# Render the data table
|
19 |
+
@output
|
20 |
+
@render.table
|
21 |
+
def table():
|
22 |
+
file = input.file()
|
23 |
+
if file is None:
|
24 |
+
return None
|
25 |
+
return pd.read_csv(file[0]['datapath'])
|
26 |
+
|
27 |
+
# Render the plot
|
28 |
+
@output
|
29 |
+
@render.plot
|
30 |
+
def plot():
|
31 |
+
file = input.file()
|
32 |
+
if file is None:
|
33 |
+
return None
|
34 |
+
|
35 |
+
df = pd.read_csv(file[0]['datapath'])
|
36 |
+
|
37 |
+
# Create matplotlib scatter plot
|
38 |
+
plt.figure(figsize=(10, 6))
|
39 |
+
plt.scatter(df[input.var1()], df[input.var2()])
|
40 |
+
plt.xlabel(input.var1())
|
41 |
+
plt.ylabel(input.var2())
|
42 |
+
plt.title(input.plot_title())
|
43 |
+
|
44 |
+
return plt.gcf()
|
45 |
+
|
46 |
+
return server
|
ui.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from shiny import ui
|
2 |
+
|
3 |
+
def create_ui():
|
4 |
+
app_ui = ui.page_fluid(
|
5 |
+
# App Title
|
6 |
+
ui.h1("Data Analysis App"),
|
7 |
+
|
8 |
+
# Layout with sidebar and main panel
|
9 |
+
ui.row(
|
10 |
+
# Sidebar panel
|
11 |
+
ui.column(4,
|
12 |
+
ui.input_file("file", "Upload CSV File",
|
13 |
+
accept=[".csv"]),
|
14 |
+
|
15 |
+
# First dropdown
|
16 |
+
ui.input_select("var1", "Select First Variable",
|
17 |
+
choices=[]),
|
18 |
+
|
19 |
+
# Second dropdown
|
20 |
+
ui.input_select("var2", "Select Second Variable",
|
21 |
+
choices=[]),
|
22 |
+
|
23 |
+
# Text input for plot title
|
24 |
+
ui.input_text("plot_title", "Enter Plot Title",
|
25 |
+
value="My Plot")
|
26 |
+
),
|
27 |
+
|
28 |
+
# Main panel with tabs
|
29 |
+
ui.column(8,
|
30 |
+
ui.navset_tab(
|
31 |
+
# Data Table tab
|
32 |
+
ui.nav_panel("Data Table",
|
33 |
+
ui.output_table("table")
|
34 |
+
),
|
35 |
+
# Plot tab
|
36 |
+
ui.nav_panel("Plot",
|
37 |
+
ui.output_plot("plot")
|
38 |
+
)
|
39 |
+
)
|
40 |
+
)
|
41 |
+
)
|
42 |
+
)
|
43 |
+
return app_ui
|