Skip to content

Commit 0e05355

Browse files
committed
Simplified layout with everything in the sidebar
1 parent 5a52067 commit 0e05355

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

app/streamlit_app.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
VD_SEED = 42
8181

82-
VD_3D = True
82+
VD_3D = False
8383

8484
# K_ are reusable keys for widgets
8585

@@ -258,13 +258,17 @@ def add_download_graph():
258258
return
259259
mapper_graph = st.session_state[S_RESULTS].mapper_graph
260260
mapper_adj = {} if mapper_graph is None else adjacency_data(mapper_graph)
261-
mapper_json = json.dumps(mapper_adj)
261+
mapper_json = json.dumps(mapper_adj, default=int)
262262
st.download_button(
263263
'📥 Download',
264264
data=get_gzip_bytes(mapper_json),
265265
disabled=mapper_graph is None,
266266
use_container_width=True,
267267
file_name=f'mapper_graph_{int(time.time())}.json.gzip')
268+
if mapper_graph is not None:
269+
nodes_num = mapper_graph.number_of_nodes()
270+
edges_num = mapper_graph.number_of_edges()
271+
st.caption(f'{nodes_num} nodes, {edges_num} edges')
268272

269273

270274
def add_data_source_csv():
@@ -297,7 +301,6 @@ def add_data_source_openml():
297301

298302

299303
def add_data_source():
300-
st.write('## 📊 Data Source')
301304
source = st.radio(
302305
'Data Source',
303306
options=['Example', 'OpenML', 'CSV'],
@@ -311,14 +314,24 @@ def add_data_source():
311314
add_data_source_example()
312315

313316

317+
def add_data_display():
318+
df_X = st.session_state[S_RESULTS].df_X
319+
df_y = st.session_state[S_RESULTS].df_y
320+
if df_X is None:
321+
return
322+
df_all = pd.concat([get_sample(df_y, frac=1.0), get_sample(df_X, frac=1.0)], axis=1)
323+
st.dataframe(df_all, height=500)
324+
325+
314326
def add_mapper_settings():
315-
st.write('## ⚙️ Mapper Settings')
316-
with st.expander('🔎 Lens'):
317-
add_lens_settings()
318-
with st.expander('🌐 Cover'):
319-
add_cover_settings()
320-
with st.expander('🧮 Clustering'):
321-
add_clustering_settings()
327+
st.markdown('🔎 Lens')
328+
add_lens_settings()
329+
st.markdown('##')
330+
st.markdown('🌐 Cover')
331+
add_cover_settings()
332+
st.markdown('##')
333+
st.markdown('🧮 Clustering')
334+
add_clustering_settings()
322335
df_X = st.session_state[S_RESULTS].df_X
323336
st.button(
324337
'✨ Run',
@@ -460,6 +473,8 @@ def render_mapper_proceed():
460473
mapper_plot = MapperLayoutInteractive(
461474
mapper_graph,
462475
dim=3 if enable_3d else 2,
476+
height=800,
477+
width=800,
463478
seed=seed)
464479
mapper_plot.update(colors=X)
465480
st.session_state[S_RESULTS].set_mapper_plot(mapper_plot)
@@ -549,37 +564,40 @@ def add_graph_plot():
549564
mapper_graph = st.session_state[S_RESULTS].mapper_graph
550565
if mapper_graph is None:
551566
return
552-
nodes_num = mapper_graph.number_of_nodes()
553-
edges_num = mapper_graph.number_of_edges()
554567
mapper_fig = st.session_state['mapper_fig']
555-
st.caption(f'{nodes_num} nodes, {edges_num} edges')
556568
st.plotly_chart(
557569
mapper_fig,
558-
use_container_width=True)
570+
use_container_width=False,
571+
config={'scrollZoom': True})
559572

560573

561574
def main():
562575
st.set_page_config(
563-
layout='wide',
576+
#layout='wide',
564577
page_icon='🍩',
565578
page_title='tda-mapper app',
566579
menu_items={
567580
'Report a bug': REPORT_BUG,
568581
'About': ABOUT
569582
})
570-
st.title('🍩 tda-mapper app')
583+
st.sidebar.title('🍩 tda-mapper app')
571584
if S_RESULTS not in st.session_state:
572585
st.session_state[S_RESULTS] = Results()
573586
with st.sidebar:
587+
tab_data_source, tab_mapper_settings, tab_draw = st.tabs([
588+
'## 📊 Data Source',
589+
'## ⚙️ Mapper Settings',
590+
'## 🎨 Draw'])
591+
with tab_data_source:
574592
add_data_source()
593+
add_data_display()
594+
with tab_mapper_settings:
575595
add_mapper_settings()
576-
col_tools, col_graph = st.columns([2, 5])
577-
with col_tools:
596+
add_download_graph()
597+
with tab_draw:
578598
add_data_tools()
579599
add_plot_setting()
580-
add_download_graph()
581-
with col_graph:
582-
add_graph_plot()
600+
add_graph_plot()
583601

584602

585603
main()

0 commit comments

Comments
 (0)