Skip to content

Commit

Permalink
factor out button function
Browse files Browse the repository at this point in the history
  • Loading branch information
mccalluc committed Nov 24, 2024
1 parent 0f63b68 commit aa53243
Showing 1 changed file with 22 additions and 42 deletions.
64 changes: 22 additions & 42 deletions dp_wizard/app/results_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit aa53243

Please sign in to comment.