Added custom delimiter.

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

48
app.py
View File

@ -66,49 +66,55 @@ st.markdown(
with Gephi and [Gephi Light](https://gephi.org/gephi-lite/).*"""
)
try:
# Print explainer.
expl = st.expander(label="More info")
with expl:
#try:
# Print explainer.
expl = st.expander(label="More info")
with expl:
st.write(info.explainer)
# Ask for nodes file.
csv_nodes = st.file_uploader(
# Ask for nodes file.
csv_nodes = st.file_uploader(
label="Upload file with **nodes** (if you have one).", key="nodes", help=f'[Example]({info.node_example})'
)
)
# Ask for relations file.
csv_edges = st.file_uploader(label="Upload file with **relations**.", key="relations", help=f'[Example]({info.relations_example})')
# Ask for relations file.
csv_edges = st.file_uploader(label="Upload file with **relations**.", key="relations", help=f'[Example]({info.relations_example})')
col1, col2 = st.columns([1,2])
col1, col2 = st.columns([1,2])
# Chose separator
with col1:
# Chose separator
with col1:
# Set standard separator.
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 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')
files_uploaded = st.button('Done', 'files_uploaded')
if files_uploaded or 'files_already_uploaded' in st.session_state:
if files_uploaded or 'files_already_uploaded' in st.session_state:
st.session_state['files_already_uploaded'] = True
if csv_edges == None:
@ -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).]')