Added custom delimiter.

This commit is contained in:
Lasse Studion 2023-05-09 08:56:50 +02:00
parent f9a9bec3f6
commit d47fc3505b

18
app.py
View File

@ -66,7 +66,7 @@ st.markdown(
with Gephi and [Gephi Light](https://gephi.org/gephi-lite/).*"""
)
try:
#try:
# Print explainer.
expl = st.expander(label="More info")
with expl:
@ -90,20 +90,26 @@ try:
st.session_state["sep"] = ','
# Ask for separator.
separators = {'comma ( , )': ',', 'semicolon ( ; )': ';', 'tab ( \u21E5 )': '\t', 'pipe (|)': '|', 'space ( )': ' ', '':''}
sep = st.radio(
'Separator in your files:',
options=['comma ( , )', 'semicolon ( ; )', 'tab ( \u21E5 )', 'pipe (|)', 'space ( )'],
options=['comma ( , )', 'semicolon ( ; )', 'tab ( \u21E5 )', 'pipe (|)', 'space ( )', 'custom'],
help='What are the values in your files separated with?'
)
if sep == 'custom':
sep = st.text_input('Custom delimiter:')
separators[sep] = sep
separators = {'comma ( , )': ',', 'semicolon ( ; )': ';', 'tab ( \u21E5 )': '\t', 'pipe (|)': '|', 'space ( )': ' '}
st.session_state["sep"] = separators[sep]
# Preview file
with col2:
preview = st.button('Preview file.')
if preview:
st.dataframe(pd.read_csv(csv_edges, sep=st.session_state["sep"]))
try:
st.dataframe(pd.read_csv(csv_edges, sep=st.session_state["sep"]), use_container_width=True)
except pd.errors.ParserError:
st.markdown(':red[Have you selected a correct separator?]')
files_uploaded = st.button('Done', 'files_uploaded')
@ -183,5 +189,5 @@ try:
)
st.write('Import the file to Gephi/Gephi Light, or try [Gephisto](https://jacomyma.github.io/gephisto/) to get an idea of the network.')
except:
st.markdown(':red[Something went wrong, please try again or [write to me](https://twitter.com/lasseedfast).]')
# except:
# st.markdown(':red[Something went wrong, please try again or [write to me](https://twitter.com/lasseedfast).]')