From aa53243fe307ee1f50d869fa232e057f4fc55ba3 Mon Sep 17 00:00:00 2001 From: Chuck McCallum Date: Sun, 24 Nov 2024 16:58:41 -0500 Subject: [PATCH] factor out button function --- dp_wizard/app/results_panel.py | 64 ++++++++++++---------------------- 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/dp_wizard/app/results_panel.py b/dp_wizard/app/results_panel.py index e970ecc..fa02296 100644 --- a/dp_wizard/app/results_panel.py +++ b/dp_wizard/app/results_panel.py @@ -16,54 +16,34 @@ wait_message = "Please wait." +def td_button(name: str, ext: str, icon: str): + function_name = f'download_{name.lower().replace(" ", "_")}' + return ( + td( + ui.download_button( + function_name, + [ + icon_svg(icon, margin_right="0.5em"), + f"Download {name} ({ext})", + ], + width="20em", + ) + ), + ) + + def results_ui(): return ui.nav_panel( "Download results", ui.markdown("You can now make a differentially private release of your data."), table( tr( - td( - ui.download_button( - "download_notebook", - [ - icon_svg("book", margin_right="0.5em"), - "Download Notebook (.ipynb)", - ], - width="20em", - ) - ), - td( - ui.download_button( - "download_script", - [ - icon_svg("python", margin_right="0.5em"), - "Download Script (.py)", - ], - width="20em", - ) - ), + td_button("Notebook", ".ipynb", "book"), + td_button("Script", ".py", "python"), ), tr( - td( - ui.download_button( - "download_txt_report", - [ - icon_svg("file-lines", margin_right="0.5em"), - "Download Report (.txt)", - ], - width="20em", - ) - ), - td( - ui.download_button( - "download_csv_report", - [ - icon_svg("file-csv", margin_right="0.5em"), - "Download Report (.csv)", - ], - width="20em", - ) - ), + td_button("Report", ".txt", "file-lines"), + td_button("Table", ".csv", "file-csv"), ), ), value="results_panel", @@ -134,7 +114,7 @@ async def download_notebook(): filename="dp-wizard-report.txt", media_type="text/plain", ) - async def download_txt_report(): + async def download_report(): with ui.Progress() as progress: progress.set(message=wait_message) notebook_nb() # Evaluate just for the side effect of creating report. @@ -147,7 +127,7 @@ async def download_txt_report(): filename="dp-wizard-report.csv", media_type="text/plain", ) - async def download_csv_report(): + async def download_table(): with ui.Progress() as progress: progress.set(message=wait_message) notebook_nb() # Evaluate just for the side effect of creating report.