Spaces:
Sleeping
Sleeping
# INSTRUCTIONS: | |
# 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu | |
# 2. run in terminal with: streamlit run app.py | |
# 3. click the "Open in Browser" link that pops up OR click on "Ports" and copy the URL | |
# 4. Open a Simple Browswer with View --> Command Palette --> Simple Browser: Show | |
# 5. use the URL from prior steps as intput into this simple browser | |
import streamlit as st | |
import altair as alt | |
from vega_datasets import data | |
st.title('My First Streamlit App') | |
st.text("The URL for this app is: https://huggingface.co/spaces/jnaiman/is445_demo") | |
source = data.seattle_weather() | |
scale = alt.Scale( | |
domain=["sun", "fog", "drizzle", "rain", "snow"], | |
range=["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"], | |
) | |
color = alt.Color("weather:N", scale=scale) | |
# We create two selections: | |
# - a brush that is active on the top panel | |
# - a multi-click that is active on the bottom panel | |
brush = alt.selection_interval(encodings=["x"]) | |
click = alt.selection_point(encodings=["color"]) | |
# Top panel is scatter plot of temperature vs time | |
points = ( | |
alt.Chart() | |
.mark_point() | |
.encode( | |
alt.X("monthdate(date):T", title="Date"), | |
alt.Y( | |
"temp_max:Q", | |
title="Maximum Daily Temperature (C)", | |
scale=alt.Scale(domain=[-5, 40]), | |
), | |
color=alt.condition(brush, color, alt.value("lightgray")), | |
size=alt.Size("precipitation:Q", scale=alt.Scale(range=[5, 200])), | |
) | |
.properties(width=550, height=300) | |
.add_params(brush) | |
.transform_filter(click) | |
) | |
# Bottom panel is a bar chart of weather type | |
bars = ( | |
alt.Chart() | |
.mark_bar() | |
.encode( | |
x="count()", | |
y="weather:N", | |
color=alt.condition(click, color, alt.value("lightgray")), | |
) | |
.transform_filter(brush) | |
.properties( | |
width=550, | |
) | |
.add_params(click) | |
) | |
chart = alt.vconcat(points, bars, data=source, title="Seattle Weather: 2012-2015") | |
tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"]) | |
with tab1: | |
st.altair_chart(chart, theme="streamlit", use_container_width=True) | |
with tab2: | |
st.altair_chart(chart, theme=None, use_container_width=True) |