Skip to content

Commit 5c8419d

Browse files
author
Gordon Shotwell
committed
Solution comments
1 parent 918e955 commit 5c8419d

File tree

21 files changed

+64
-13
lines changed

21 files changed

+64
-13
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Modify the app to add "Hello World" to the main heading.
1+
Modify the app to add "Hello World!" to the main heading.
2+
Click the play button to run the app.

apps/problem-sets/1-getting-started/1.1-data-frame/app-solution.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
df = pd.read_csv(infile)
77
df = df.drop(columns=["text"])
88

9+
# The render.data_frame decorator is used to display dataframes.
10+
911

1012
@render.data_frame
1113
def penguins_df():

apps/problem-sets/1-getting-started/1.2-debug/app-solution.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
df = df.drop(columns=["text"])
88

99

10+
# It's important that you use the right decorator for your funciton's return value
11+
# in this case since the function is returning a dataframe we need to use the
12+
# `@render.data_frame` decorator.
1013
@render.data_frame
1114
def penguins_df():
1215
return df

apps/problem-sets/1-getting-started/1.3-filter-input/app-solution.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
from pathlib import Path
44
from data_import import df
55

6+
# All the inputs start with `ui.input_*`, which adds an input to the app.
7+
# Note that this input doesn't do anything because we haven't connected it
8+
# to a rendering function.
9+
610
ui.input_select(
7-
"account",
8-
"Account",
11+
id="account",
12+
label="Account",
913
choices=[
1014
"Berge & Berge",
1115
"Fritsch & Fritsch",

apps/problem-sets/1-getting-started/1.4-filter-connect/app-solution.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from data_import import df
55

66
ui.input_select(
7-
"account",
8-
"Account",
7+
id="account",
8+
label="Account",
99
choices=[
1010
"Berge & Berge",
1111
"Fritsch & Fritsch",
@@ -18,8 +18,13 @@
1818

1919
@render.data_frame
2020
def table():
21+
# When we call the account input with `input.account()` we can use its value
22+
# with regular Python code. This will also cause the rendering function
23+
# to rerun whenever the user changes the account value.
2124
account_subset = df[df["account"] == input.account()]
2225
account_counts = (
23-
account_subset.groupby("sub_account").size().reset_index(name="counts")
26+
account_subset.groupby(["account", "sub_account"])
27+
.size()
28+
.reset_index(name="count")
2429
)
2530
return account_counts

apps/problem-sets/1-getting-started/1.4-filter-connect/app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from data_import import df
55

66
ui.input_select(
7-
"account",
8-
"Account",
7+
id="account",
8+
label="Account",
99
choices=[
1010
"Berge & Berge",
1111
"Fritsch & Fritsch",
@@ -20,6 +20,8 @@
2020
def table():
2121
account_subset = df
2222
account_counts = (
23-
account_subset.groupby("sub_account").size().reset_index(name="counts")
23+
account_subset.groupby(["account", "sub_account"])
24+
.size()
25+
.reset_index(name="count")
2426
)
2527
return account_counts

apps/problem-sets/1-getting-started/1.5-debug/app-solution.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
@render.data_frame
2020
def table():
21+
# Remember that inputs are callable values, so whenever you refer to them
22+
# in rendering functions you need to call them (`input.account()` not `input.account`)
2123
account_subset = df[df["account"] == input.account()]
2224
account_counts = (
2325
account_subset.groupby("sub_account").size().reset_index(name="counts")

apps/problem-sets/1-getting-started/1.6-debug/app-solution.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
@render.data_frame
2020
def table():
21+
# Inputs can only be called within a reactive context, which
22+
# means that if you refer to them outside of a rendering function
23+
# you'll get an error.
2124
account_subset = df[df["account"] == input.account()]
2225
account_counts = (
2326
account_subset.groupby("sub_account").size().reset_index(name="counts")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add a second plot output to the app which plots the precision-recall curve. Note that you should use the `@render_plotly` decorator.
1+
Use the `plot_precision_recall_curve` function from the `plots.py` module to add a second plot output to the app. Note that you should use the `@render_plotly` decorator

apps/problem-sets/1-getting-started/1.7-add-plot/app-solution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
],
1616
)
1717

18-
18+
# It's a good idea to use helper functions for things like drawing plots
19+
# or displaying data frames because it makes your app more modular and easy to
20+
# read.
1921
@render_plotly
2022
def precision_recall_plot():
2123
account_subset = df[df["account"] == input.account()]

0 commit comments

Comments
 (0)