Skip to content

Commit 5635a68

Browse files
committed
add new first and last episodes
1 parent ceca9b0 commit 5635a68

14 files changed

+203
-62
lines changed

_episodes/.gitkeep

Whitespace-only changes.

_episodes/00-the-why-of-interactivity.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

_episodes/01-why-interactivity.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: "Why make interactive visualizations?"
3+
teaching: 10
4+
exercises: 0
5+
questions:
6+
- "Why are visual representations of data useful when trying to see patterns?"
7+
- "Why do we want to make visualizations interactive?"
8+
- "Consider the message you want to convey or story you want to tell. Is it clearer with some interactivity?"
9+
objectives:
10+
- "To understand the difference between static and interactive plots"
11+
- "To understand why we may want to make plots interactive"
12+
- "To introduce what we will be doing in this workshop lesson"
13+
keypoints:
14+
- "Visualization is an important part of both exploratory data analysis and communicating results"
15+
- "Interactivity allows us to visualize more information without overcomplicating a single plot"
16+
---
17+
18+
## Why do we like visualizations?
19+
20+
Visualization is often one of the first and most vital steps of exploratory data analysis.
21+
People benefit from visual representation of data to see patterns, and plotting data is also an important part of a researcher's communication toolbox.
22+
Interactive visualizations can be used both during the initial exploratory phase and the final publication and communication phase of a research project.
23+
24+
> ## Discuss: visualizations in research publications
25+
>
26+
> When was the last time you saw a research paper without figures?
27+
>
28+
> When reading research do you start with the figures?
29+
>
30+
> How would the recent publications you have studied have made sense if you couldn't see the figures?
31+
{: .discussion}
32+
33+
## Choices in analysis and presentation
34+
35+
Producing a figure will often depend on the story you want to tell, or the pattern you wish to highlight in your data.
36+
37+
Any one visualization is limited in how many attributes can (and should) be represented. For example, if you have a scatterplot and assign one attribute to x-axis, one attribute to the y-axis (maybe even one to the z-axis!), another attribute to the color, yet another attribute to the shape, and even another attribute to the size... you may be able to cram a lot of information into the plot, but the resulting visualization will probably not tell a clear story.
38+
39+
Any one visualization is limited in how many different attributes can be reasonably included. Modern data sets are often too dense to visualize without making a lot of these choices.
40+
41+
But with an interactive plot, we can include all of this information - just not at the same time. Rather than being forced to choose which few attributes to represent and communicate, you can allow the audience to choose the information they are interested in seeing, with the possibility they will choose to explore all of the possible visualizations.
42+
43+
The magic of interactivity is that you don't have to limit yourself and your plots - you can visualize it all! However, you should carefully consider the options for your interactive visualizations so that they are still telling a cohesive story about the data.
44+
45+
Interactivity gives the audience a chance to explore the data in ways a static (non-interactive) plot does not. It can also help you and your collaborators understand your data better.
46+
47+
> ## There are many options for making figures with Python
48+
>
49+
> This tutorial makes use of Plotly and Streamlit, but a range of options now exist for visualizing data in the Python ecosystem.
50+
>
51+
> These are summarized at [PyViz.org](https://pyviz.org/tools.html).
52+
>
53+
> Many of the tools described are developed with specific users in mind, whereas others are intentionally more basic and adaptable. Some are focused on particular issues, such as choices of color or the aggregation of data. There is a lot here to explore!
54+
{: .callout}
55+
56+
## How will we build our interactive visualization app?
57+
58+
1. Create a new and squeaky clean python environment that has only the packages we need
59+
2. Use pandas to wrangle our data into a tidy format
60+
3. Create some initial visualizations and learn how to use Plotly Express
61+
4. Create a basic streamlit app (no interactivity yet!) with one of those initial visualizations
62+
5. Go back through our code to refactor (reorganize) some hardcoded information into more flexible variables
63+
6. Add widgets! These are what allow our app to be truly interactive and allow users to adjust the displayed plots
64+
7. Deploy the app - so everyone can see what you created.
65+
8. (Optionally) Put your own creative spin on it - add some of your own widgets and visualizations to make your app unique
66+
67+
68+
{% include links.md %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Create a New Environment"
3-
teaching: 10
3+
teaching: 20
44
exercises: 0
55
questions:
66
- "How can I create a new conda environment?"
File renamed without changes.
File renamed without changes.
File renamed without changes.

_episodes/08-publish-your-app.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
title: "Publish Your Streamlit App"
3+
teaching: 20
4+
exercises: 0
5+
questions:
6+
- "How do I deploy my app so other people can see it?"
7+
- "How do I create a `requirements.txt` file?"
8+
objectives:
9+
- "Learn how to deploy a Streamlit app"
10+
keypoints:
11+
- "All Streamlit apps must have a GitHub repo with the code, data, and environment files"
12+
- "You can deploy up to 3 apps for free with Streamlit Cloud"
13+
---
14+
15+
Now that we have our final app, it's time to publish (a.k.a deploy) it so that other people can see and interact with the visualizations.
16+
17+
## Create a GitHub repo
18+
19+
The first step is to create a new GitHub repository that will contain the code, data, and environment files.
20+
21+
> ## Refresher on creating GitHub repos
22+
> If you have not created a GitHub repository before or need a refresher, please refer to [this episode on Remotes in GitHub](https://swcarpentry.github.io/git-novice/07-github/index.html) from the Software Carpentries lesson [Version Control with Git](https://swcarpentry.github.io/git-novice/)
23+
{: .callout}
24+
25+
Give your repo a descriptive name, like `interact-with-gapminder-data-app`. Make sure that the repo is "Public" (not Private) and check the box to initialize the repo with a README.md.
26+
27+
Once your repo is created, clone a copy of it to your local computer. You can use the application GitHub Desktop to more easily accomplish this. You can download GitHub Desktop [here](https://desktop.github.com).
28+
29+
Now that you have a copy of your repo on your computer, you can copy over your code and data files.
30+
31+
## Copy over the code and data files
32+
33+
During this workshop, we have created some Jupyter Notebooks files and an `app.py` file. We don't need the Jupyter Notebooks to be a part of the app's repo, only the `app.py` file.
34+
35+
Remember that at the start of the `app.py` file, we import our data with the line:
36+
37+
~~~
38+
df = pd.read_csv("Data/gapminder_tidy.csv")
39+
~~~
40+
{: .language-python}
41+
42+
So, we also need to make sure to include the `Data` folder and the `gapminder_tidy.csv` file inside of it.
43+
44+
You can copy these files using a GUI (Finder on Macs or Explorer on PCs) or the command line, whatever you are comfortable with.
45+
46+
Let's suppose that your repo is named `interact-with-gapminder-data-app`, and it has been cloned to the `GitHub` folder in your `Documents`. So, the location of your local repo is `~/Documents/GitHub/interact-with-gapminder-data-app`. So far, we have been working from the `Desktop`, in a folder called `data_viz_workshop`. Using the command line, we can copy the relevant files with:
47+
48+
~~~
49+
cp ~/Desktop/data_viz_workshop/app.py ~/Documents/GitHub/interact-with-gapminder-data-app/app.py
50+
mkdir ~/Documents/GitHub/interact-with-gapminder-data-app/Data
51+
cp ~/Desktop/data_viz_workshop/Data/gapminder_tidy.csv ~/Documents/GitHub/interact-with-gapminder-data-app/Data/gapminder_tidy.csv
52+
~~~
53+
{: .language-bash}
54+
55+
Your interact-with-gapminder-data-app folder should now look like:
56+
57+
~~~
58+
interact-with-gapminder-data-app
59+
│ README.md
60+
│ app.py
61+
62+
└───Data
63+
│ gapminder_tidy.csv
64+
~~~
65+
{: .output}
66+
67+
We're almost done! But we need to do one more thing... specify an environment for the app to run in.
68+
69+
## Add a requirements.txt file
70+
71+
In order for our app to run on Streamlit's servers, we need to tell it what the environment should look like - or what packages need to be installed. While there are many standards for describing a python environment (such as the `environment.yml` file we used to create our conda environment at the beginning of this workshop), Streamlit tends to work best with a `requirements.txt` file.
72+
73+
The `requirements.txt` file is just a list of package names and version numbers, with each line looking like `packagename==version.number.here`. And there is no need to list out all of the packages, just the top-level ones. The dependencies will get installed for each listed package as well.
74+
75+
The `requirements.txt` file should be kept in the root of your repository. So, after creating a requirements file your repo should look like:
76+
77+
~~~
78+
interact-with-gapminder-data-app
79+
│ README.md
80+
│ requirements.txt
81+
│ app.py
82+
83+
└───Data
84+
│ gapminder_tidy.csv
85+
~~~
86+
{: .output}
87+
88+
For our app, we only need to specify two packages: Streamlit and Plotly. Note that you may have different version numbers. Here is an example of our `requirements.txt` file:
89+
90+
~~~
91+
streamlit==1.1.0
92+
plotly==5.1.0
93+
~~~
94+
{: .source}
95+
96+
## Push the updated repo
97+
98+
Now that we have our code, data, and environment files added to our local copy of the repository, it's time to push our repo to GitHub. You can use GitHub Desktop or use git from the command line to accomplish this. If you have unwanted extra files (like `.DS_Store`) added to the directory, make sure to add them to a `.gitignore` file!
99+
100+
Once you have added, committed, and pushed your changes (with a descriptive commit message!) go to your GitHub repo online to double check that it is up to date.
101+
102+
Now we are ready to deploy the app!
103+
104+
## Sign up for Streamlit Cloud (Community Tier)
105+
106+
Follow the steps detailed on Streamlit's Documentation to sign up for a free Streamlit Cloud account and connect it to your GitHub account. The documentation is located [here](https://docs.streamlit.io/streamlit-cloud/get-started).
107+
108+
You can sign up for a Streamlit Cloud account at [share.streamlit.io/](https://share.streamlit.io/).
109+
110+
On the free Community tier, you can deploy up to 3 apps at once. If you later decide to build more Streamlit apps, you can remove this one.
111+
112+
## Deploy your app
113+
114+
When you have signed in to your Streamlit account, click "New app". Copy and paste your GitHub repo URL, for example `https://github.com/username/interact-with-gapminder-data-app`, specify the correct branch name (which is most likely `main`), and specify the filename of your app (`app.py`). Then click "Deploy", and wait for the balloons!
115+
116+
You can read the documentation about this process for deploying an app [here](https://docs.streamlit.io/streamlit-cloud/get-started/deploy-an-app).
117+
118+
{% include links.md %}
119+

0 commit comments

Comments
 (0)