Spaces:
Build error
Build error
qua605
commited on
Commit
·
bfd3c5f
1
Parent(s):
6d660c5
Check if working
Browse files
app.py
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import altair as alt
|
| 3 |
+
from vega_datasets import data
|
| 4 |
+
|
| 5 |
+
st.title('Streamlit App for IS445: ID9518')
|
| 6 |
+
|
| 7 |
+
st.text("The URL for this app is: https://huggingface.co/spaces/fallinginfall65/is445_demo")
|
| 8 |
+
|
| 9 |
+
source = data.seattle_weather()
|
| 10 |
+
|
| 11 |
+
scale = alt.Scale(
|
| 12 |
+
domain=["sun", "fog", "drizzle", "rain", "snow"],
|
| 13 |
+
range=["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"],
|
| 14 |
+
)
|
| 15 |
+
color = alt.Color("weather:N", scale=scale)
|
| 16 |
+
|
| 17 |
+
# We create two selections:
|
| 18 |
+
# - a brush that is active on the top panel
|
| 19 |
+
# - a multi-click that is active on the bottom panel
|
| 20 |
+
brush = alt.selection_interval(encodings=["x"])
|
| 21 |
+
click = alt.selection_point(encodings=["color"])
|
| 22 |
+
|
| 23 |
+
# Top panel is scatter plot of temperature vs time
|
| 24 |
+
points = (
|
| 25 |
+
alt.Chart()
|
| 26 |
+
.mark_point()
|
| 27 |
+
.encode(
|
| 28 |
+
alt.X("monthdate(date):T", title="Date (Month Year)"),
|
| 29 |
+
alt.Y(
|
| 30 |
+
"temp_max:Q",
|
| 31 |
+
title="Maximum Daily Temperature (C)",
|
| 32 |
+
scale=alt.Scale(domain=[-5, 40]),
|
| 33 |
+
),
|
| 34 |
+
color=alt.condition(brush, color, alt.value("lightgray")),
|
| 35 |
+
size=alt.Size("precipitation:Q", scale=alt.Scale(range=[5, 200])),
|
| 36 |
+
)
|
| 37 |
+
.properties(width=550, height=300)
|
| 38 |
+
.add_params(brush)
|
| 39 |
+
.transform_filter(click)
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
# Bottom panel is a bar chart of weather type
|
| 43 |
+
bars = (
|
| 44 |
+
alt.Chart()
|
| 45 |
+
.mark_bar()
|
| 46 |
+
.encode(
|
| 47 |
+
x="count()",
|
| 48 |
+
y="weather:N",
|
| 49 |
+
color=alt.condition(click, color, alt.value("lightgray")),
|
| 50 |
+
)
|
| 51 |
+
.transform_filter(brush)
|
| 52 |
+
.properties(
|
| 53 |
+
width=550,
|
| 54 |
+
)
|
| 55 |
+
.add_params(click)
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
chart = alt.vconcat(points, bars, data=source, title="Seattle Weather - 2019 to 2025")
|
| 59 |
+
|
| 60 |
+
tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])
|
| 61 |
+
|
| 62 |
+
with tab1:
|
| 63 |
+
st.altair_chart(chart, theme="streamlit", use_container_width=True)
|
| 64 |
+
with tab2:
|
| 65 |
+
st.altair_chart(chart, theme=None, use_container_width=True)
|