统一使用start.sh启动

两个demo页面
This commit is contained in:
leo
2023-12-31 17:57:17 +08:00
parent e3dabed229
commit c3b1983b30
8 changed files with 94 additions and 64 deletions

View File

@@ -1,47 +0,0 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import streamlit as st
import pandas as pd
import numpy as np
def get_data():
df = pd.DataFrame({
"lat": np.random.randn(200) / 50 + 37.76,
"lon": np.random.randn(200) / 50 + -122.4,
"team": ['A', 'B'] * 100
})
return df
if st.button('Generate new points'):
st.session_state.df = get_data()
if 'df' not in st.session_state:
st.session_state.df = get_data()
df = st.session_state.df
with st.form("my_form"):
header = st.columns([1, 2, 2])
header[0].subheader('Color')
header[1].subheader('Opacity')
header[2].subheader('Size')
row1 = st.columns([1, 2, 2])
colorA = row1[0].color_picker('Team A', '#0000FF')
opacityA = row1[1].slider('A opacity', 20, 100, 50, label_visibility='hidden')
sizeA = row1[2].slider('A size', 50, 200, 100, step=10, label_visibility='hidden')
row2 = st.columns([1, 2, 2])
colorB = row2[0].color_picker('Team B', '#FF0000')
opacityB = row2[1].slider('B opacity', 20, 100, 50, label_visibility='hidden')
sizeB = row2[2].slider('B size', 50, 200, 100, step=10, label_visibility='hidden')
st.form_submit_button('Update map')
alphaA = int(opacityA * 255 / 100)
alphaB = int(opacityB * 255 / 100)
df['color'] = np.where(df.team == 'A', colorA + f'{alphaA:02x}', colorB + f'{alphaB:02x}')
df['size'] = np.where(df.team == 'A', sizeA, sizeB)
st.map(df, size='size', color='color')

8
pages/test.py Normal file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import streamlit as st
st.write('Hello World!')
for i in range(1, 13):
st.write(f"{i}. this is line {i}")

View File

@@ -0,0 +1,31 @@
import random
import streamlit as st
import pandas as pd
import numpy as np
if "counter" not in st.session_state:
st.session_state.counter = 0
st.session_state.counter += 1
st.header(f"This page has run {st.session_state.counter} times.")
st.button("Run it again")
if "df" not in st.session_state:
st.session_state.df = pd.DataFrame(np.random.randn(20, 2), columns=["x", "y"])
if "color" not in st.session_state:
st.session_state.color = "#FF0000"
def generate_random_color():
rand_color = "#{:06x}".format(random.randint(0, 0xFFFFFF))
st.session_state.color = rand_color.upper()
st.header("Choose a datapoint color")
st.color_picker("Color", "#FF0000", key="color")
st.button("random color", key="random_color", on_click=generate_random_color)
st.divider()
st.scatter_chart(st.session_state.df, x="x", y="y", color=st.session_state.color)