Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
st.set_page_config(layout="centered")
|
5 |
+
|
6 |
+
@st.cache_data(show_spinner=False)
|
7 |
+
def load_data(file_path):
|
8 |
+
dataset = pd.read_csv(file_path)
|
9 |
+
return dataset
|
10 |
+
|
11 |
+
|
12 |
+
@st.cache_data(show_spinner=False)
|
13 |
+
def split_frame(input_df, rows):
|
14 |
+
df = [input_df.loc[i : i + rows - 1, :] for i in range(0, len(input_df), rows)]
|
15 |
+
return df
|
16 |
+
|
17 |
+
|
18 |
+
file_path = st.file_uploader("Select CSV file to upload", type=["csv"])
|
19 |
+
if file_path:
|
20 |
+
dataset = load_data(file_path)
|
21 |
+
top_menu = st.columns(3)
|
22 |
+
with top_menu[0]:
|
23 |
+
sort = st.radio("Sort Data", options=["Yes", "No"], horizontal=1, index=1)
|
24 |
+
if sort == "Yes":
|
25 |
+
with top_menu[1]:
|
26 |
+
sort_field = st.selectbox("Sort By", options=dataset.columns)
|
27 |
+
with top_menu[2]:
|
28 |
+
sort_direction = st.radio(
|
29 |
+
"Direction", options=["⬆️", "⬇️"], horizontal=True
|
30 |
+
)
|
31 |
+
dataset = dataset.sort_values(
|
32 |
+
by=sort_field, ascending=sort_direction == "⬆️", ignore_index=True
|
33 |
+
)
|
34 |
+
pagination = st.container()
|
35 |
+
|
36 |
+
bottom_menu = st.columns((4, 1, 1))
|
37 |
+
with bottom_menu[2]:
|
38 |
+
batch_size = st.selectbox("Page Size", options=[25, 50, 100])
|
39 |
+
with bottom_menu[1]:
|
40 |
+
total_pages = (
|
41 |
+
int(len(dataset) / batch_size) if int(len(dataset) / batch_size) > 0 else 1
|
42 |
+
)
|
43 |
+
current_page = st.number_input(
|
44 |
+
"Page", min_value=1, max_value=total_pages, step=1
|
45 |
+
)
|
46 |
+
with bottom_menu[0]:
|
47 |
+
st.markdown(f"Page **{current_page}** of **{total_pages}** ")
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
pages = split_frame(dataset, batch_size)
|
52 |
+
pagination.dataframe(data=pages[current_page - 1], use_container_width=True)
|