| |
| |
| |
| |
| |
| |
|
|
|
|
| import streamlit as st |
| import altair as alt |
| from vega_datasets import data |
| |
| st.title('Streamlit App for IS445: ID45086') |
|
|
| st.text("The URL for this app is: https://huggingface.co/spaces/SharanyaBhardwaj/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) |
|
|
| |
| |
| |
| brush = alt.selection_interval(encodings=["x"]) |
| click = alt.selection_point(encodings=["color"]) |
|
|
| |
| points = ( |
| alt.Chart() |
| .mark_point() |
| .encode( |
| alt.X("monthdate(date):T", title="Date (Month Year)"), |
| 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) |
| ) |
|
|
| |
| 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 - 2011 to 2013") |
|
|
| 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) |