diff --git a/apps/problem-sets/1-getting-started/1.1-data-frame/app.py b/apps/problem-sets/1-getting-started/1.1-data-frame/app.py index ec31ada..d09790b 100644 --- a/apps/problem-sets/1-getting-started/1.1-data-frame/app.py +++ b/apps/problem-sets/1-getting-started/1.1-data-frame/app.py @@ -4,6 +4,7 @@ infile = Path(__file__).parent / "simulated-data.csv" df = pd.read_csv(infile) +df = df.drop(columns=["text"]) @render.____ diff --git a/apps/problem-sets/1-getting-started/1.3-filter-input/README b/apps/problem-sets/1-getting-started/1.3-filter-input/README index ad0badf..61ddbf4 100644 --- a/apps/problem-sets/1-getting-started/1.3-filter-input/README +++ b/apps/problem-sets/1-getting-started/1.3-filter-input/README @@ -1,3 +1,2 @@ Add a select input to the app which lets the user select one of the accounts. For reference the account list is: -`["Berge & Berge", "Fritsch & Fritsch", "Hintz & Hintz", "Mosciski and Sons", "Wolff Ltd"` - ]` \ No newline at end of file +`["Berge & Berge", "Fritsch & Fritsch", "Hintz & Hintz", "Mosciski and Sons", "Wolff Ltd"]` \ No newline at end of file diff --git a/apps/problem-sets/1-getting-started/1.4-filter-connect/app.py b/apps/problem-sets/1-getting-started/1.4-filter-connect/app.py index ba1b0c7..94ef74f 100644 --- a/apps/problem-sets/1-getting-started/1.4-filter-connect/app.py +++ b/apps/problem-sets/1-getting-started/1.4-filter-connect/app.py @@ -1,4 +1,4 @@ -from shiny.express import render, ui +from shiny.express import render, ui, input import pandas as pd from pathlib import Path from data_import import df @@ -18,5 +18,8 @@ @render.data_frame def table(): - account_counts = df.groupby("sub_account").size().reset_index(name="counts") + account_subset = df + account_counts = ( + account_subset.groupby("sub_account").size().reset_index(name="counts") + ) return account_counts diff --git a/apps/problem-sets/1-getting-started/1.7-add-plot/app-solution.py b/apps/problem-sets/1-getting-started/1.7-add-plot/app-solution.py index ca40f6d..06681d9 100644 --- a/apps/problem-sets/1-getting-started/1.7-add-plot/app-solution.py +++ b/apps/problem-sets/1-getting-started/1.7-add-plot/app-solution.py @@ -16,15 +16,6 @@ ) -@render.data_frame -def table(): - account_subset = df[df["account"] == input.account()] - account_counts = ( - account_subset.groupby("sub_account").size().reset_index(name="counts") - ) - return account_counts - - @render_plotly def precision_recall_plot(): account_subset = df[df["account"] == input.account()] diff --git a/apps/problem-sets/3-reactivity/3.2-stacking-reactives/README b/apps/problem-sets/3-reactivity/3.2-stacking-reactives/README index db6aeb4..747e33f 100644 --- a/apps/problem-sets/3-reactivity/3.2-stacking-reactives/README +++ b/apps/problem-sets/3-reactivity/3.2-stacking-reactives/README @@ -1,5 +1,5 @@ We have a second sidebad input which allows the user to filter the dataset by the number of characters in the `text` field. Add a second reactive calculation to the app which filters the `account_data()` reactive. -For `input.chars()` returns a tuple with the lower and upper range of a value, and you can filter the data frame with: +For reference `input.chars()` returns a tuple with the lower and upper range of a value, and you can filter the data frame with: `df[df["text"].str.len().between(*input.chars()]`. diff --git a/apps/problem-sets/3-reactivity/3.2-stacking-reactives/app-solution.py b/apps/problem-sets/3-reactivity/3.2-stacking-reactives/app-solution.py index 317d293..1667929 100644 --- a/apps/problem-sets/3-reactivity/3.2-stacking-reactives/app-solution.py +++ b/apps/problem-sets/3-reactivity/3.2-stacking-reactives/app-solution.py @@ -12,7 +12,7 @@ def account_data(): @reactive.calc() def character_filter(): - return account_data()[(account_data()["text"].str.len().between(*input.chars()))] + return account_data()[account_data()["text"].str.len().between(*input.chars())] with ui.sidebar(): diff --git a/apps/problem-sets/3-reactivity/3.2-stacking-reactives/app.py b/apps/problem-sets/3-reactivity/3.2-stacking-reactives/app.py index de4ec2f..18dd1af 100644 --- a/apps/problem-sets/3-reactivity/3.2-stacking-reactives/app.py +++ b/apps/problem-sets/3-reactivity/3.2-stacking-reactives/app.py @@ -4,6 +4,12 @@ from plots import plot_auc_curve, plot_precision_recall_curve, plot_score_distribution from shinywidgets import render_plotly + +@reactive.calc +def account_data(): + return df[df["account"] == input.account()] + + with ui.sidebar(): ui.input_select( "account", @@ -32,14 +38,11 @@ @render_plotly def metric(): - account_subset = df[df["account"] == input.account()] if input.metric() == "ROC Curve": - return plot_auc_curve( - account_subset, "is_electronics", "training_score" - ) + return plot_auc_curve(account_data, "is_electronics", "training_score") else: return plot_precision_recall_curve( - account_subset, "is_electronics", "training_score" + account_data(), "is_electronics", "training_score" ) ui.input_select("metric", "Metric", choices=["ROC Curve", "Precision Recall"]) @@ -49,5 +52,4 @@ def metric(): @render_plotly def score_dist(): - account_subset = df[df["account"] == input.account()] - return plot_score_distribution(account_subset) + return plot_score_distribution(account_data()) diff --git a/exercises/1-hello-world.qmd b/exercises/1-hello-world.qmd index 32b211e..711a123 100644 --- a/exercises/1-hello-world.qmd +++ b/exercises/1-hello-world.qmd @@ -11,7 +11,6 @@ from helpers import problem_tabs ``` -# Exercise 1.0 - Hello World ```{python} # | echo: false diff --git a/helpers.py b/helpers.py index b46a71f..d088bff 100644 --- a/helpers.py +++ b/helpers.py @@ -124,8 +124,11 @@ def find_problem_set_folder(base_path, target_path): path = find_problem_set_folder("apps/problem-sets", folder_name) + formatted_title = "## " + folder_name.replace("-", " ").title() + block = QuartoPrint( [ + formatted_title, "::::: {.column-screen-inset}", "::: {.panel-tabset}", "## Goal",