Skip to content

Commit d2f133f

Browse files
committed
Add download to csv and align buttons
1 parent 0e4f7d8 commit d2f133f

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

panel/app.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import matplotlib.pyplot as plt
88
import numpy as np
99
import pandas as pd
10+
from pandas.io.formats.style import Styler
1011
import panel as pn
1112
from panel.layout.gridstack import GridStack
1213

@@ -228,6 +229,19 @@ def tableau_states(res, states):
228229
return styler
229230

230231

232+
def csv_data(
233+
sensitivity_indices: pn.widgets.Tabulator, scenario: Styler, states: Styler
234+
) -> io.StringIO:
235+
sio = io.StringIO()
236+
237+
sensitivity_indices.value.to_csv(sio)
238+
scenario.data.to_csv(sio)
239+
states.data.to_csv(sio)
240+
241+
sio.seek(0)
242+
return sio
243+
244+
231245
# Bindings
232246
text_fname = pn.widgets.FileInput(sizing_mode="stretch_width", accept=".csv")
233247

@@ -397,13 +411,43 @@ def tableau_states(res, states):
397411
gstack.servable(title="Simulation Decomposition Dashboard")
398412

399413
# Header
414+
icon_size = "1.5em"
415+
416+
download_file_button = pn.widgets.FileDownload(
417+
callback=pn.bind(
418+
csv_data,
419+
interactive_sensitivity_indices_table,
420+
interactive_tableau,
421+
interactive_tableau_states,
422+
),
423+
icon="file-download",
424+
icon_size=icon_size,
425+
button_type="success",
426+
filename="simdec.csv",
427+
width=150,
428+
height_policy="min",
429+
label="Download",
430+
styles={"margin-top": "0"},
431+
# align="center" # does not work
432+
)
433+
400434
info_button = pn.widgets.Button(
401-
icon="info-circle", button_type="light", name="More info", width=150
435+
icon="info-circle",
436+
icon_size=icon_size,
437+
button_type="light",
438+
name="More info",
439+
width=150,
440+
align="center",
402441
)
403442
info_button.js_on_click(code="""window.location.href = 'https://www.simdec.fi/'""")
404443

405444
issue_button = pn.widgets.Button(
406-
icon="bug", button_type="danger", name="Report an issue", width=200
445+
icon="bug",
446+
icon_size=icon_size,
447+
button_type="danger",
448+
name="Report an issue",
449+
width=200,
450+
align="center",
407451
)
408452
issue_button.js_on_click(
409453
code="""window.location.href = 'https://github.com/Simulation-Decomposition/simdec-python/issues'"""
@@ -414,6 +458,7 @@ def tableau_states(res, states):
414458

415459
pn.Row(
416460
pn.HSpacer(),
461+
download_file_button,
417462
info_button,
418463
issue_button,
419464
# logout_button,

0 commit comments

Comments
 (0)