Spaces:
Runtime error
Runtime error
File size: 3,941 Bytes
45e5a75 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
import streamlit as st
import pandas as pd
###################################
from st_aggrid import AgGrid
from st_aggrid.grid_options_builder import GridOptionsBuilder
from st_aggrid.shared import JsCode
###################################
from functionforDownloadButtons import download_button
###################################
def _max_width_():
max_width_str = f"max-width: 1800px;"
st.markdown(
f"""
<style>
.reportview-container .main .block-container{{
{max_width_str}
}}
</style>
""",
unsafe_allow_html=True,
)
st.set_page_config(page_icon="✂️", page_title="CSV Wrangler")
# st.image("https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/285/balloon_1f388.png", width=100)
st.image(
"https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/285/scissors_2702-fe0f.png",
width=100,
)
st.title("CSV Wrangler")
# st.caption(
# "PRD : TBC | Streamlit Ag-Grid from Pablo Fonseca: https://pypi.org/project/streamlit-aggrid/"
# )
# ModelType = st.radio(
# "Choose your model",
# ["Flair", "DistilBERT (Default)"],
# help="At present, you can choose between 2 models (Flair or DistilBERT) to embed your text. More to come!",
# )
# with st.expander("ToDo's", expanded=False):
# st.markdown(
# """
# - Add pandas.json_normalize() - https://streamlit.slack.com/archives/D02CQ5Z5GHG/p1633102204005500
# - **Remove 200 MB limit and test with larger CSVs**. Currently, the content is embedded in base64 format, so we may end up with a large HTML file for the browser to render
# - **Add an encoding selector** (to cater for a wider array of encoding types)
# - **Expand accepted file types** (currently only .csv can be imported. Could expand to .xlsx, .txt & more)
# - Add the ability to convert to pivot → filter → export wrangled output (Pablo is due to change AgGrid to allow export of pivoted/grouped data)
# """
# )
#
# st.text("")
c29, c30, c31 = st.columns([1, 6, 1])
with c30:
uploaded_file = st.file_uploader(
"",
key="1",
help="To activate 'wide mode', go to the hamburger menu > Settings > turn on 'wide mode'",
)
if uploaded_file is not None:
file_container = st.expander("Check your uploaded .csv")
shows = pd.read_csv(uploaded_file)
uploaded_file.seek(0)
file_container.write(shows)
else:
st.info(
f"""
👆 Upload a .csv file first. Sample to try: [biostats.csv](https://people.sc.fsu.edu/~jburkardt/data/csv/biostats.csv)
"""
)
st.stop()
from st_aggrid import GridUpdateMode, DataReturnMode
gb = GridOptionsBuilder.from_dataframe(shows)
# enables pivoting on all columns, however i'd need to change ag grid to allow export of pivoted/grouped data, however it select/filters groups
gb.configure_default_column(enablePivot=True, enableValue=True, enableRowGroup=True)
gb.configure_selection(selection_mode="multiple", use_checkbox=True)
gb.configure_side_bar() # side_bar is clearly a typo :) should by sidebar
gridOptions = gb.build()
st.success(
f"""
💡 Tip! Hold the shift key when selecting rows to select multiple rows at once!
"""
)
response = AgGrid(
shows,
gridOptions=gridOptions,
enable_enterprise_modules=True,
update_mode=GridUpdateMode.MODEL_CHANGED,
data_return_mode=DataReturnMode.FILTERED_AND_SORTED,
fit_columns_on_grid_load=False,
)
df = pd.DataFrame(response["selected_rows"])
st.subheader("Filtered data will appear below 👇 ")
st.text("")
st.table(df)
st.text("")
c29, c30, c31 = st.columns([1, 1, 2])
with c29:
CSVButton = download_button(
df,
"File.csv",
"Download to CSV",
)
with c30:
CSVButton = download_button(
df,
"File.csv",
"Download to TXT",
) |