jnaiman commited on
Commit
adf30a2
1 Parent(s): 9010db6
prep/Hello.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+
4
+ st.set_page_config(
5
+ page_title="Hello",
6
+ page_icon="👋",
7
+ )
8
+
9
+ st.sidebar.success("Select a Page")
10
+
11
+ st.title('This is my fancy title for my main page!')
12
+
13
+ # after this point, things will be a little different if you are on PL or running the code locally on your computer
14
+ # I'll be running locally usually, but let's look at PL first:
15
+
16
+ # INSTRUCTIONS FOR RUNNING ON PL:
17
+ # 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu
18
+ # 2. run in terminal with: "streamlit run <the app .py file>"
19
+ # 3. click the "Open in Browser" link that pops up OR click on "Ports" and copy the URL
20
+ # 4. Open a Simple Browswer with View --> Command Palette --> Simple Browser: Show
21
+ # 5. use the URL from prior steps as intput into this simple browser
22
+
23
+ ### 1.1 Text in Streamlit ###
24
+ # Let's look at a few more ways to include text in our Streamlit apps.
25
+ # We usually start our app with a title (like what we had above).
26
+ # We can also have headers and subheaders.
27
+ # See: https://docs.streamlit.io/develop/api-reference/text
28
+
29
+ st.header('This is a "header"')
30
+ st.subheader('This is a "subheader"')
31
+
32
+ # On the docs there are several other ways to use text (like LaTeX and Markdown),
33
+ # but we'll usually just be using the plain text:
34
+ st.text("This is plain text.")
35
+
36
+ # You can also use "magic" commands like:
37
+ 'This is also plain text!!'
38
+
39
+ # ... but we will be using the "write" command typically for consistency:
40
+ st.write('This is also some text.')
41
+
42
+ # ... or often we will use Markdown:
43
+ st.markdown("""
44
+ I can also use markdown to write stuff!
45
+ """)
46
+
47
+ # You should do whatever makes sense to you!
48
+
49
+ ### 1.2 Layout elements ###
50
+ st.subheader('Layouts')
51
+ # There are several different ways we can layout our text/charts.
52
+ # See: https://docs.streamlit.io/develop/api-reference/layout
53
+
54
+ col1, col2 = st.columns(2)
55
+ col1.write('This is me adding in some text to column 1')
56
+ col2.write('This is me adding in some text to column 2')
57
+
58
+ # Note that in theory we can have multiple columns, but in practice
59
+ # the columns will "wrap" after a certain number by default.
60
+
61
+ # There is a lot of fun stuff here to play with in layouts!
62
+ # For our purposes, we'll start off with some of the simple defaults.
63
+
64
+ ### 1.3 Images ###
65
+ st.subheader('Images')
66
+ # We can include images with a URL:
67
+ st.image('https://i.redd.it/on-a-scale-of-1-10-how-derpy-is-she-v0-z8gtdwu5n5zb1.jpg?width=3024&format=pjpg&auto=webp&s=345e7e1d5b45f20c733e497a9f746f4cbd3a61da',
68
+ width=400,
69
+ caption='A thinly veiled excuse to include a derpy corgi.')
prep/README.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Streamlit Template (Shadi's Class)
3
+ emoji: 🏢
4
+ colorFrom: blue
5
+ colorTo: gray
6
+ sdk: streamlit
7
+ sdk_version: 1.39.0
8
+ app_file: Hello.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+ # Install what you need for this notebook
16
+
17
+ It is recommended you install into a conda environment:
18
+
19
+ ```
20
+ conda create -n DataVizClass python=3.10
21
+ conda activate DataVizClass
22
+ ```
23
+
24
+ Then you can install the correct packages. If you have downloaded the requirements document you can install directly with:
25
+
26
+ ```
27
+ pip install -r /path/to/requirements.txt
28
+ ```
29
+
30
+ Or you can install one by one with:
31
+
32
+ ```
33
+ pip install streamlit==1.39.0 altair numpy pandas matplotlib
34
+ ```
35
+
36
+ To work with the VSCode interface, be sure that `jupyter` is also installed:
37
+
38
+ ```
39
+ pip install jupyter
40
+ ```
41
+
42
+ Or you can install with `conda`.
43
+
44
+ Note that the package [Streamlit](https://streamlit.io/) that we will be working with requires we use Python scripts, so JupyterLab and/or Jupyter Notebooks won't work for this process.
prep/pages/1_Data_Introduction.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.set_page_config(page_title="Introduction to Data", page_icon=":1234:") # not sure what this adds?
4
+ st.sidebar.header("Introduction to Data")
5
+
6
+ st.title('This is a title for Data Exploration')
7
+
8
+ mobility_url = 'https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/mobility.csv'
9
+
10
+ st.write("Here is where we could give some background about our dataset.")
11
+ st.write("This would be a good place to include links, references, and images.")
12
+
13
+ import pandas as pd
14
+ df = pd.read_csv(mobility_url)
15
+
16
+ # There are a few ways to show the dataframe if we want our viewer to see the table:
17
+ #df
18
+ st.write(df)
prep/pages/2_Widget_Exploration.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.set_page_config(page_title="Widget Exploration", page_icon=":1234:")
4
+ st.sidebar.header("Widget Exploration")
5
+
6
+ st.header("Simple Widgets")
7
+
8
+ st.write("How great are you feeling right now?")
9
+ sentiment_mapping = ["one", "two", "three", "four", "five"] # map to these numers
10
+ selected = st.feedback("stars")
11
+ if selected is not None: # make sure we have a selection
12
+ st.markdown(f"You selected {sentiment_mapping[selected]} star(s).")
13
+ if selected < 1:
14
+ st.markdown('Sorry to hear you are so sad :(')
15
+ elif selected < 3:
16
+ st.markdown('A solid medium is great!')
17
+ else:
18
+ st.markdown('Fantastic you are having such a great day!')
19
+
20
+
21
+
22
+ st.header("Tying Widgets to Pandas/Matplotlib Plots")
23
+
24
+ # we can also tie widget interaction to plots
25
+
26
+ # first, let's just try a simple plot with pandas
27
+ import pandas as pd
28
+ import matplotlib.pyplot as plt
29
+
30
+ df = pd.read_csv("https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/mobility.csv")
31
+
32
+ # let's first make a plot
33
+ fig,ax = plt.subplots() # this changed
34
+ df.groupby('State')['Mobility'].mean().plot(kind='bar',ax=ax)
35
+
36
+ st.pyplot(fig) # this is different
37
+
38
+ # now, let's remake this plot, but allow for some interactivity by only
39
+ # selecting a subset of states to plot
40
+ # multi-select
41
+ states_selected = st.multiselect('Which states do you want to view?', df['State'].unique())
42
+
43
+ if len(states_selected) > 0: # if selected
44
+ df_subset = df[df['State'].isin(states_selected)]
45
+
46
+ fig2,ax2 = plt.subplots() # this changed
47
+ df_subset.groupby('State')['Mobility'].mean().plot(kind='bar',ax=ax2)
48
+
49
+ st.pyplot(fig2) # this is different
50
+ else: # otherwise plot all states
51
+ fig2,ax2 = plt.subplots() # this changed
52
+ df.groupby('State')['Mobility'].mean().plot(kind='bar',ax=ax2)
53
+ st.pyplot(fig2) # this is different
prep/pages/3_Other_Tools.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.set_page_config(page_title="Other Tools", page_icon=":1234:")
4
+ st.sidebar.header("Other Tools")
5
+
6
+ st.title("Other cool things to check out")
7
+
8
+ st.markdown(""" While we won't have time to cover everything, a few things you might want to check out later:
9
+ 1. You can connect databases to Streamlit [like AWS, MongoDB, etc](https://docs.streamlit.io/develop/tutorials/databases)
10
+ 1. You can embed Streamlit Spaces [within other webpages](https://huggingface.co/docs/hub/en/spaces-sdks-streamlit#embed-streamlit-spaces-on-other-webpages)
11
+ 1. If you have models hosted on HuggingFace, you can build [apps that use those models](https://huggingface.co/blog/streamlit-spaces) (like LLMs) and let others use them.
12
+ """)
prep/requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit==1.39.0
2
+ altair
3
+ numpy
4
+ pandas
5
+ matplotlib