Spaces:
Sleeping
Sleeping
in class changes
Browse files- app.py +0 -73
- inClass_script_week10.py +29 -1
app.py
DELETED
@@ -1,73 +0,0 @@
|
|
1 |
-
# INSTRUCTIONS:
|
2 |
-
# 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu
|
3 |
-
# 2. run in terminal with: streamlit run app.py
|
4 |
-
# 3. click the "Open in Browser" link that pops up OR click on "Ports" and copy the URL
|
5 |
-
# 4. Open a Simple Browswer with View --> Command Palette --> Simple Browser: Show
|
6 |
-
# 5. use the URL from prior steps as intput into this simple browser
|
7 |
-
|
8 |
-
|
9 |
-
import streamlit as st
|
10 |
-
import altair as alt
|
11 |
-
from vega_datasets import data
|
12 |
-
|
13 |
-
st.title('My First Streamlit App')
|
14 |
-
|
15 |
-
st.text("The URL for this app is: https://huggingface.co/spaces/jnaiman/is445_demo")
|
16 |
-
|
17 |
-
source = data.seattle_weather()
|
18 |
-
|
19 |
-
scale = alt.Scale(
|
20 |
-
domain=["sun", "fog", "drizzle", "rain", "snow"],
|
21 |
-
range=["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"],
|
22 |
-
)
|
23 |
-
color = alt.Color("weather:N", scale=scale)
|
24 |
-
|
25 |
-
# We create two selections:
|
26 |
-
# - a brush that is active on the top panel
|
27 |
-
# - a multi-click that is active on the bottom panel
|
28 |
-
brush = alt.selection_interval(encodings=["x"])
|
29 |
-
click = alt.selection_point(encodings=["color"])
|
30 |
-
|
31 |
-
# Top panel is scatter plot of temperature vs time
|
32 |
-
points = (
|
33 |
-
alt.Chart()
|
34 |
-
.mark_point()
|
35 |
-
.encode(
|
36 |
-
alt.X("monthdate(date):T", title="Date"),
|
37 |
-
alt.Y(
|
38 |
-
"temp_max:Q",
|
39 |
-
title="Maximum Daily Temperature (C)",
|
40 |
-
scale=alt.Scale(domain=[-5, 40]),
|
41 |
-
),
|
42 |
-
color=alt.condition(brush, color, alt.value("lightgray")),
|
43 |
-
size=alt.Size("precipitation:Q", scale=alt.Scale(range=[5, 200])),
|
44 |
-
)
|
45 |
-
.properties(width=550, height=300)
|
46 |
-
.add_params(brush)
|
47 |
-
.transform_filter(click)
|
48 |
-
)
|
49 |
-
|
50 |
-
# Bottom panel is a bar chart of weather type
|
51 |
-
bars = (
|
52 |
-
alt.Chart()
|
53 |
-
.mark_bar()
|
54 |
-
.encode(
|
55 |
-
x="count()",
|
56 |
-
y="weather:N",
|
57 |
-
color=alt.condition(click, color, alt.value("lightgray")),
|
58 |
-
)
|
59 |
-
.transform_filter(brush)
|
60 |
-
.properties(
|
61 |
-
width=550,
|
62 |
-
)
|
63 |
-
.add_params(click)
|
64 |
-
)
|
65 |
-
|
66 |
-
chart = alt.vconcat(points, bars, data=source, title="Seattle Weather: 2012-2015")
|
67 |
-
|
68 |
-
tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])
|
69 |
-
|
70 |
-
with tab1:
|
71 |
-
st.altair_chart(chart, theme="streamlit", use_container_width=True)
|
72 |
-
with tab2:
|
73 |
-
st.altair_chart(chart, theme=None, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inClass_script_week10.py
CHANGED
@@ -48,4 +48,32 @@ col1,col2 = st.columns([0.7, 0.25])
|
|
48 |
col1.altair_chart(scatters, theme='streamlit',
|
49 |
use_container_width=True)
|
50 |
col2.markdown("Here is some text on the side of the plot.")
|
51 |
-
col2.image('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQAXjp6mzNlkMEEiMomUfTEMiX8NHpopoyyXg&s')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
col1.altair_chart(scatters, theme='streamlit',
|
49 |
use_container_width=True)
|
50 |
col2.markdown("Here is some text on the side of the plot.")
|
51 |
+
col2.image('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQAXjp6mzNlkMEEiMomUfTEMiX8NHpopoyyXg&s')
|
52 |
+
|
53 |
+
|
54 |
+
st.header("Day 2 (Week 11)")
|
55 |
+
|
56 |
+
# Read in data with pandas
|
57 |
+
import pandas as pd
|
58 |
+
df = pd.read_csv(mobility_url)
|
59 |
+
|
60 |
+
#df
|
61 |
+
st.write(df)
|
62 |
+
|
63 |
+
import matplotlib.pyplot as plt
|
64 |
+
fig, ax = plt.subplots()
|
65 |
+
df['Seg_income'].plot(kind='hist',ax=ax)
|
66 |
+
#plt.show() # need to use streamlit infrastructure for this
|
67 |
+
st.pyplot(fig)
|
68 |
+
|
69 |
+
st.write("""Note I have added some things to
|
70 |
+
the requirements.txt file. """)
|
71 |
+
st.code("""
|
72 |
+
streamlit==1.39.0
|
73 |
+
altair
|
74 |
+
numpy
|
75 |
+
matplotlib
|
76 |
+
pandas
|
77 |
+
""")
|
78 |
+
|
79 |
+
st.header("Widgets in Streamlit apps")
|