Spaces:
Sleeping
Sleeping
test
Browse filesFiles changed (2)
- requirements.txtAdded+3
- test_altair_streamlit.pyAdded+71
123streamlitaltairvega_datasets1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071# INSTRUCTIONS:# 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu# 2. run in terminal with: streamlit run test_altair_streamlit.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 stimport altair as altfrom vega_datasets import data st.title('My First Streamlit App')
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 panelbrush = alt.selection_interval(encodings=["x"])click = alt.selection_point(encodings=["color"])
# Top panel is scatter plot of temperature vs timepoints = ( 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 typebars = ( 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)requirements.txtAdded+3
test_altair_streamlit.pyAdded+71