Skip to content

Commit c7417b2

Browse files
committed
final polishing/updating for new episodes
add time estimates for exercises
1 parent 5635a68 commit c7417b2

File tree

6 files changed

+52
-25
lines changed

6 files changed

+52
-25
lines changed

_episodes/03-data-wrangling.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Data Wrangling"
33
teaching: 15
4-
exercises: 0
4+
exercises: 5
55
questions:
66
- "What format should my data be in for Plotly Express?"
77
- "Why can't I use the data in its current format?"
@@ -26,17 +26,15 @@ You can click on the `Data` folder and double click on `gapminder_all.csv` to vi
2626
We are going take this very wide dataset and make it very long, so the unit of observation will be each country + year + metric combination, rather than just the country. This process is made much simpler by a couple of functions in the `pandas` library.
2727

2828
> ## Tidy Data
29+
>
2930
> The term "tidy data" may be most popular in the R ecosystem (the "tidyverse" is a collection of R packages designed around the tidy data philosophy), but it is applicable to all tabular datasets, not matter what programming language you are using to wrangle your data.
30-
> You can ready more about the tidy data philosophy in Hadley Wickham's 2014 paper, "Tidy Data", available [here](https://vita.had.co.nz/papers/tidy-data.pdf).
3131
>
32-
> Tidy data follows 3 rules:
33-
> 1. Each variable forms a column
34-
> 2. Each observation forms a row
35-
> 3. Each type of observational unit forms a table
32+
> You can ready more about the tidy data philosophy in Hadley Wickham's 2014 paper, "Tidy Data", available [here](https://vita.had.co.nz/papers/tidy-data.pdf).
3633
>
3734
> Wickham later refined and revised the tidy data philosophy, and published it in the 12th chapter of his open access textbook "R for Data Science" - available [here](https://r4ds.had.co.nz/tidy-data.html).
3835
>
3936
> The revised rules are:
37+
>
4038
> 1. Each variable must have its own column
4139
> 2. Each observation must have its own row
4240
> 3. Each value must have its own cell
@@ -75,6 +73,7 @@ df
7573
The first function we are going to use to wrangle this dataset is `pd.melt()`. This function's entire purpose to to make wide dataframes into long dataframes.
7674

7775
> ## Check out the documentation
76+
>
7877
> To learn more about `pd.melt()`, you can look at the function's [documentation](https://pandas.pydata.org/docs/reference/api/pandas.melt.html)
7978
> To see this documentation within Jupyter Lab, you can type `pd.melt()` in a cell and then hold down the shift + tab keys.
8079
> You can also open a "Show Contextual Help" window from the Launcher.
@@ -91,7 +90,6 @@ df.columns
9190

9291
Our "id" columns are `country` and `continent`. Our "value" columns are all of the rest. That's a lot of columns! But no worries - we can programmatically make a list of all of these columns.
9392

94-
9593
~~~
9694
cols = list(df.columns)
9795
cols.remove('continent')
@@ -109,6 +107,7 @@ df_melted
109107
{: .language-python}
110108

111109
> ## New dataframe variable names
110+
>
112111
> When wrangling a dataframe in a Jupyter notebook, it's a good idea to assign transformed dataframes to a new variable name.
113112
> You don't have to do this with every transformation, but do try to do this with every substantial transformation.
114113
> This way, we don't have to re-run the entire notebook when we are experimenting with transformations on a dataframe.
@@ -127,6 +126,7 @@ df_melted
127126
{: .language-python}
128127

129128
> ## Wide vs long data
129+
>
130130
> Take a moment to compare this dataframe to the one we started with.
131131
>
132132
> What are some advantages to having the data in this format?
@@ -152,6 +152,8 @@ df_final.to_csv("Data/gapminder_tidy.csv", index=False)
152152

153153
We set the index to False so that the index column does not get saved to the CSV file.
154154

155+
## Exercises
156+
155157
> ## Imagining other tidy ways to wrangle
156158
> We wrangled our data into a tidy form. However, there is no single "true tidy" form for any given dataset.
157159
>

_episodes/04-create-visualizations.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Create Visualizations"
3-
teaching: 10
4-
exercises: 0
3+
teaching: 15
4+
exercises: 5
55
questions:
66
- "How can I create an interactive visualization using Plotly Express?"
77
objectives:
@@ -80,7 +80,6 @@ fig.show()
8080

8181
There it is! Our first line plot.
8282

83-
8483
## When you want to compare - adding more lines and labels
8584

8685
By itself, this plot of New Zealand's GDP isn't especially interesting. Let's add another line, to compare it to Australia.
@@ -116,6 +115,7 @@ fig.show()
116115
![Plot of Oceania's GDP over time with correct labels](../fig/L3_thirdplot.png)
117116

118117
> ## Interactivity is baked in to Plotly charts
118+
>
119119
> When you have many more lines, the interactive features of Plotly become very useful.
120120
> Notice how hovering over a line will tell you more information about that point.
121121
> You will also see several options in the upper right corner to further interact with the plot - including saving it as a PNG file!
@@ -124,6 +124,7 @@ fig.show()
124124
## Exercises
125125

126126
> ## Visualize Population in Europe
127+
>
127128
> Create a plot that visualizes the population of countries in Europe over time.
128129
> > ## Solution
129130
> > ~~~
@@ -136,6 +137,7 @@ fig.show()
136137
{: .challenge}
137138
138139
> ## Visualize Average Life Expectancy in Asia
140+
>
139141
> Create a plot that visualizes the average life expectancy of countries in Asia over time.
140142
> > ## Solution
141143
> > ~~~

_episodes/05-create-streamlit-app.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Create the Streamlit App"
3-
teaching: 10
4-
exercises: 0
3+
teaching: 15
4+
exercises: 5
55
questions:
66
- "How do I create a Streamlit app?"
77
- "How can I see a live preview of my app?"
@@ -109,8 +109,9 @@ You can make this title whatever you want. Save the file, and go back to the bro
109109
We can add other text to our app with `st.write()` and other functions.
110110

111111
> ## Check out the documentation
112+
>
112113
> Whenever you are working with a new library - or even one that you are familiar with! - it's a good idea to look through the documentation.
113-
> You can find Streamlit's documentation [here](https://docs.streamlit.io/en/stable/api.html#)
114+
> You can find Streamlit's documentation [here](https://docs.streamlit.io/library/api-reference)
114115
{: .callout}
115116

116117
## Add a plot to the app
@@ -158,16 +159,10 @@ We now have a web application that can allow you to share your interactive visua
158159

159160
![Streamlit app after this lesson](../fig/streamlit_app_lesson4fin.png)
160161

161-
> ## Share your app online
162-
> Right now, our app only lives on our computer. Like Jupyter Lab, the app is displaying in a web browser but has the URL `localhost:####` (where #### represents the port number).
163-
> To easily make this app public and shared online, you can sign up for a [Streamlit Sharing](https://streamlit.io/sharing-sign-up) account. This will let you share up to 3 apps.
164-
> All you need (in addition to an account) is to have your code in a public GitHub repo.
165-
> Detailed instructions can be found in [Streamlit's Documentation](https://docs.streamlit.io/en/stable/deploy_streamlit_app.html)
166-
{: .callout}
167-
168162
## Exercises
169163

170164
> ## Add a description
165+
>
171166
> After the plot is displayed, add some text describing the plot.
172167
> > ## Solution
173168
> > ~~~
@@ -179,6 +174,7 @@ We now have a web application that can allow you to share your interactive visua
179174
{: .challenge}
180175
181176
> ## Show me the data!
177+
>
182178
> After the plot is displayed, also display the dataframe used to generate the plot.
183179
> > ## Solution
184180
> > ~~~

_episodes/06-refactoring-for-flexibility.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Refactoring Code for Flexibility (Prepping for Widgets)"
3-
teaching: 15
4-
exercises: 0
3+
teaching: 20
4+
exercises: 5
55
questions:
66
- "How does the current code need to change in order to incorporate widgets?"
77
- "What aspects of the code need to change?"
@@ -243,6 +243,7 @@ st.plotly_chart(fig, use_container_width=True)
243243
## Exercises
244244

245245
> ## Add a (flexible) description
246+
>
246247
> After the plot is displayed, add some text describing the plot.
247248
>
248249
> This time, use F-strings so the description can change with the plot
@@ -255,6 +256,7 @@ st.plotly_chart(fig, use_container_width=True)
255256
{: .challenge}
256257
257258
> ## Show me the data! (Maybe)
259+
>
258260
> After the plot is displayed, also display the dataframe used to generate the plot.
259261
>
260262
> This time, make it optional - only display the dataframe if a variable is set to True.

_episodes/07-add-widgets.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Add Widgets to the Streamlit App"
3-
teaching: 10
4-
exercises: 0
3+
teaching: 15
4+
exercises: 15
55
questions:
66
- "Why do I want to have widgets in my app?"
77
- "What kinds of widgets are there?"
@@ -23,6 +23,7 @@ We are going to add two widgets to our app. One widget will let us select the co
2323
You may have said "Dropdown box". In Streamlit, this is called a "Select box", and is created with `st.selectbox()`.
2424

2525
> ## Look through the documentation for widget options
26+
>
2627
> Streamlit has many types of widgets available. You can see the documentation for them [here](https://docs.streamlit.io/en/stable/api.html#display-interactive-widgets)
2728
{: .callout}
2829

@@ -174,6 +175,7 @@ Save, Rerun, and... Share!
174175
## Exercises
175176

176177
> ## Show me the data! (If the user wants it)
178+
>
177179
> After the plot is displayed, also display the dataframe used to generate the plot.
178180
>
179181
> Use a widget so that the user can decide whether to display the data.
@@ -192,6 +194,7 @@ Save, Rerun, and... Share!
192194
{: .challenge}
193195
194196
> ## Limit the countries displayed in the plot
197+
>
195198
> Add a widget that allows users to limit the countries that will be displayed on the plot.
196199
>
197200
> (Hint: look at the multiselect!)
@@ -209,6 +212,7 @@ Save, Rerun, and... Share!
209212
{: .challenge}
210213
211214
> ## Limit the dates displayed in the plot
215+
>
212216
> Add a widget that allows users to limit the range of years that will be displayed on the plot.
213217
>
214218
> (Hint: look at the slider!)
@@ -227,6 +231,7 @@ Save, Rerun, and... Share!
227231
{: .challenge}
228232
229233
> ## Improve the description
234+
>
230235
> After the plot is displayed, add some text describing the plot.
231236
>
232237
> This time, add more to the description based on the information specified by the newly added widgets.

_episodes/08-publish-your-app.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Publish Your Streamlit App"
33
teaching: 20
4-
exercises: 0
4+
exercises: 30
55
questions:
66
- "How do I deploy my app so other people can see it?"
77
- "How do I create a `requirements.txt` file?"
@@ -115,5 +115,25 @@ When you have signed in to your Streamlit account, click "New app". Copy and pas
115115

116116
You can read the documentation about this process for deploying an app [here](https://docs.streamlit.io/streamlit-cloud/get-started/deploy-an-app).
117117

118+
## Exercises
119+
120+
> ## Add your own twist
121+
>
122+
> Now that you have successfully deployed the app we created together, it's time for you to add your own twist.
123+
>
124+
> You can add more visualizations, more widgets, or make use of Streamlit's other capabilities to add to and enhance the app. Make it your own!
125+
{: .challenge}
126+
127+
> ## Share & Present Your Apps
128+
>
129+
> After everyone has had time to work on adding their own twist to their Streamlit apps, take some time to share your apps with each other and present what was added to the base app.
130+
>
131+
> What did you find challenging?
132+
>
133+
> What feature that you added did you most like?
134+
>
135+
> What is something else you would like to add in the future?
136+
{: .discussion}
137+
118138
{% include links.md %}
119139

0 commit comments

Comments
 (0)