timmy 修订了这个 Gist 10 months ago. 转到此修订
1 file changed, 19 insertions
streamlit_data_visualization.py(文件已创建)
| @@ -0,0 +1,19 @@ | |||
| 1 | + | import streamlit as st | |
| 2 | + | import pandas as pd | |
| 3 | + | import numpy as np | |
| 4 | + | ||
| 5 | + | st.write("Streamlit supports a wide range of data visualizations, including [Plotly, Altair, and Bokeh charts](https://docs.streamlit.io/develop/api-reference/charts). 📊 And with over 20 input widgets, you can easily make your data interactive!") | |
| 6 | + | ||
| 7 | + | all_users = ["Alice", "Bob", "Charly"] | |
| 8 | + | with st.container(border=True): | |
| 9 | + | users = st.multiselect("Users", all_users, default=all_users) | |
| 10 | + | rolling_average = st.toggle("Rolling average") | |
| 11 | + | ||
| 12 | + | np.random.seed(42) | |
| 13 | + | data = pd.DataFrame(np.random.randn(20, len(users)), columns=users) | |
| 14 | + | if rolling_average: | |
| 15 | + | data = data.rolling(7).mean().dropna() | |
| 16 | + | ||
| 17 | + | tab1, tab2 = st.tabs(["Chart", "Dataframe"]) | |
| 18 | + | tab1.line_chart(data, height=250) | |
| 19 | + | tab2.dataframe(data, height=250, use_container_width=True) | |
上一页
下一页