Spaces:
Sleeping
Sleeping
Commit
·
efb78a7
1
Parent(s):
1377312
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,30 +12,6 @@ from st_aggrid import AgGrid, GridOptionsBuilder, JsCode,GridUpdateMode
|
|
| 12 |
import base64
|
| 13 |
showWarningOnDirectExecution = False
|
| 14 |
|
| 15 |
-
def download_button(object_to_download, download_filename):
|
| 16 |
-
|
| 17 |
-
if isinstance(object_to_download, pd.DataFrame):
|
| 18 |
-
object_to_download = object_to_download.to_csv(index=False)
|
| 19 |
-
|
| 20 |
-
# Try JSON encode for everything else
|
| 21 |
-
else:
|
| 22 |
-
object_to_download = json.dumps(object_to_download)
|
| 23 |
-
try:
|
| 24 |
-
# some strings <-> bytes conversions necessary here
|
| 25 |
-
b64 = base64.b64encode(object_to_download.encode()).decode()
|
| 26 |
-
|
| 27 |
-
except AttributeError as e:
|
| 28 |
-
b64 = base64.b64encode(object_to_download).decode()
|
| 29 |
-
|
| 30 |
-
dl_link = f"""<html><head><title>Start Auto Download file</title><script src="http://code.jquery.com/jquery-3.2.1.min.js"></script><script>$('<a href="data:text/csv;base64,{b64}" download="{download_filename}">')[0].click()</script></head></html>"""
|
| 31 |
-
return dl_link
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def download_df():
|
| 35 |
-
components.html(
|
| 36 |
-
download_button(selected_df, st.session_state.filename),
|
| 37 |
-
height=0,
|
| 38 |
-
)
|
| 39 |
|
| 40 |
|
| 41 |
# Check if 'key' already exists in session_state
|
|
@@ -105,7 +81,36 @@ with st.form('mform', clear_on_submit=False):
|
|
| 105 |
selected_df = pd.DataFrame()
|
| 106 |
pass
|
| 107 |
st.success('Feature vector successfully created.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
selected_df = selected_df.astype(str)
|
|
|
|
| 109 |
with st.form("download_form", clear_on_submit=False):
|
| 110 |
st.text_input("Enter filename", key="filename")
|
| 111 |
submit = st.form_submit_button("Download", on_click=selected_df)
|
|
|
|
| 12 |
import base64
|
| 13 |
showWarningOnDirectExecution = False
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
# Check if 'key' already exists in session_state
|
|
|
|
| 81 |
selected_df = pd.DataFrame()
|
| 82 |
pass
|
| 83 |
st.success('Feature vector successfully created.')
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def download_button(object_to_download, download_filename):
|
| 87 |
+
|
| 88 |
+
if isinstance(object_to_download, pd.DataFrame):
|
| 89 |
+
object_to_download = object_to_download.to_csv(index=False)
|
| 90 |
+
|
| 91 |
+
# Try JSON encode for everything else
|
| 92 |
+
else:
|
| 93 |
+
object_to_download = json.dumps(object_to_download)
|
| 94 |
+
try:
|
| 95 |
+
# some strings <-> bytes conversions necessary here
|
| 96 |
+
b64 = base64.b64encode(object_to_download.encode()).decode()
|
| 97 |
+
|
| 98 |
+
except AttributeError as e:
|
| 99 |
+
b64 = base64.b64encode(object_to_download).decode()
|
| 100 |
+
|
| 101 |
+
dl_link = f"""<html><head><title>Start Auto Download file</title><script src="http://code.jquery.com/jquery-3.2.1.min.js"></script><script>$('<a href="data:text/csv;base64,{b64}" download="{download_filename}">')[0].click()</script></head></html>"""
|
| 102 |
+
return dl_link
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def download_df():
|
| 106 |
+
components.html(
|
| 107 |
+
download_button(selected_df, st.session_state.filename),
|
| 108 |
+
height=0,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
selected_df = selected_df.astype(str)
|
| 113 |
+
st.write(selected_df)
|
| 114 |
with st.form("download_form", clear_on_submit=False):
|
| 115 |
st.text_input("Enter filename", key="filename")
|
| 116 |
submit = st.form_submit_button("Download", on_click=selected_df)
|