Skip to content

Commit

Permalink
merge #16 and #17
Browse files Browse the repository at this point in the history
  • Loading branch information
mccalluc committed Sep 30, 2024
2 parents b235279 + 1b4f9fc commit a1e41a0
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source = .

omit =
# TODO
app.py
dp_creator_ii/app/*

# More strict: Check transitions between lines, not just individual lines.
# TODO: branch = True
Expand Down
23 changes: 23 additions & 0 deletions dp_creator_ii/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from shiny import App, ui

from dp_creator_ii.app import analysis_panel, dataset_panel, results_panel


app_ui = ui.page_bootstrap(
ui.navset_tab(
dataset_panel.dataset_ui(),
analysis_panel.analysis_ui(),
results_panel.results_ui(),
id="top_level_nav",
),
title="DP Creator II",
)


def server(input, output, session):
dataset_panel.dataset_server(input, output, session)
analysis_panel.analysis_server(input, output, session)
results_panel.results_server(input, output, session)


app = App(app_ui, server)
17 changes: 17 additions & 0 deletions dp_creator_ii/app/analysis_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from shiny import ui, reactive


def analysis_ui():
return ui.nav_panel(
"Perform Analysis",
"TODO: Define analysis",
ui.input_action_button("go_to_results", "Download results"),
value="analysis_panel",
)


def analysis_server(input, output, session):
@reactive.effect
@reactive.event(input.go_to_results)
def go_to_results():
ui.update_navs("top_level_nav", selected="results_panel")
34 changes: 34 additions & 0 deletions dp_creator_ii/app/dataset_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pathlib import Path
import json
from shiny import ui, reactive, render
from dp_creator_ii import get_arg_parser


def dataset_ui():
return ui.nav_panel(
"Select Dataset",
"TODO: Pick dataset",
ui.output_text("csv_path_text"),
ui.output_text("unit_of_privacy_text"),
ui.input_action_button("go_to_analysis", "Perform analysis"),
value="dataset_panel",
)


def dataset_server(input, output, session):
args = get_arg_parser().parse_args()
csv_path = reactive.value(args.csv_path)
unit_of_privacy = reactive.value(args.unit_of_privacy)

@render.text
def csv_path_text():
return str(csv_path.get())

@render.text
def unit_of_privacy_text():
return str(unit_of_privacy.get())

@reactive.effect
@reactive.event(input.go_to_analysis)
def go_to_analysis():
ui.update_navs("top_level_nav", selected="analysis_panel")
63 changes: 3 additions & 60 deletions dp_creator_ii/app.py → dp_creator_ii/app/results_panel.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
from shiny import App, ui, reactive, render
from shiny import ui, render

from dp_creator_ii import get_arg_parser
from dp_creator_ii.template import make_notebook_py, make_script_py
from dp_creator_ii.converters import convert_py_to_nb


def dataset_panel():
return ui.nav_panel(
"Select Dataset",
"TODO: Pick dataset",
ui.output_text("csv_path_text"),
ui.output_text("unit_of_privacy_text"),
ui.input_action_button("go_to_analysis", "Perform analysis"),
value="dataset_panel",
)


def analysis_panel():
return ui.nav_panel(
"Perform Analysis",
"TODO: Define analysis",
ui.input_action_button("go_to_results", "Download results"),
value="analysis_panel",
)


def results_panel():
def results_ui():
return ui.nav_panel(
"Download Results",
"TODO: Download Results",
Expand All @@ -41,41 +21,7 @@ def results_panel():
)


app_ui = ui.page_bootstrap(
ui.navset_tab(
dataset_panel(),
analysis_panel(),
results_panel(),
id="top_level_nav",
),
title="DP Creator II",
)


def server(input, output, session):
args = get_arg_parser().parse_args()

csv_path = reactive.value(args.csv_path)
unit_of_privacy = reactive.value(args.unit_of_privacy)

@render.text
def csv_path_text():
return str(csv_path.get())

@render.text
def unit_of_privacy_text():
return str(unit_of_privacy.get())

@reactive.effect
@reactive.event(input.go_to_analysis)
def go_to_analysis():
ui.update_navs("top_level_nav", selected="analysis_panel")

@reactive.effect
@reactive.event(input.go_to_results)
def go_to_results():
ui.update_navs("top_level_nav", selected="results_panel")

def results_server(input, output, session):
@render.download(
filename="dp-creator-script.py",
media_type="text/x-python",
Expand Down Expand Up @@ -115,6 +61,3 @@ async def download_notebook_executed():
)
notebook_nb = convert_py_to_nb(notebook_py, execute=True)
yield notebook_nb


app = App(app_ui, server)
2 changes: 1 addition & 1 deletion dp_creator_ii/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from shiny.pytest import create_app_fixture


app = create_app_fixture("../app.py")
app = create_app_fixture("../app/__init__.py")


# TODO: Why is incomplete coverage reported here?
Expand Down

0 comments on commit a1e41a0

Please sign in to comment.