Added custom delimiter.
This commit is contained in:
parent
f9a9bec3f6
commit
d47fc3505b
48
app.py
48
app.py
@ -66,49 +66,55 @@ st.markdown(
|
|||||||
with Gephi and [Gephi Light](https://gephi.org/gephi-lite/).*"""
|
with Gephi and [Gephi Light](https://gephi.org/gephi-lite/).*"""
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
#try:
|
||||||
# Print explainer.
|
# Print explainer.
|
||||||
expl = st.expander(label="More info")
|
expl = st.expander(label="More info")
|
||||||
with expl:
|
with expl:
|
||||||
st.write(info.explainer)
|
st.write(info.explainer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Ask for nodes file.
|
# Ask for nodes file.
|
||||||
csv_nodes = st.file_uploader(
|
csv_nodes = st.file_uploader(
|
||||||
label="Upload file with **nodes** (if you have one).", key="nodes", help=f'[Example]({info.node_example})'
|
label="Upload file with **nodes** (if you have one).", key="nodes", help=f'[Example]({info.node_example})'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Ask for relations file.
|
# Ask for relations file.
|
||||||
csv_edges = st.file_uploader(label="Upload file with **relations**.", key="relations", help=f'[Example]({info.relations_example})')
|
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
|
# Chose separator
|
||||||
with col1:
|
with col1:
|
||||||
# Set standard separator.
|
# Set standard separator.
|
||||||
st.session_state["sep"] = ','
|
st.session_state["sep"] = ','
|
||||||
|
|
||||||
# Ask for separator.
|
# Ask for separator.
|
||||||
|
separators = {'comma ( , )': ',', 'semicolon ( ; )': ';', 'tab ( \u21E5 )': '\t', 'pipe (|)': '|', 'space ( )': ' ', '':''}
|
||||||
sep = st.radio(
|
sep = st.radio(
|
||||||
'Separator in your files:',
|
'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?'
|
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]
|
st.session_state["sep"] = separators[sep]
|
||||||
|
|
||||||
# Preview file
|
# Preview file
|
||||||
with col2:
|
with col2:
|
||||||
preview = st.button('Preview file.')
|
preview = st.button('Preview file.')
|
||||||
if preview:
|
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
|
st.session_state['files_already_uploaded'] = True
|
||||||
|
|
||||||
if csv_edges == None:
|
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.')
|
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:
|
# except:
|
||||||
st.markdown(':red[Something went wrong, please try again or [write to me](https://twitter.com/lasseedfast).]')
|
# st.markdown(':red[Something went wrong, please try again or [write to me](https://twitter.com/lasseedfast).]')
|
Loading…
x
Reference in New Issue
Block a user