Skip to content

Commit

Permalink
Fixing the session state/widget keys so that the app actually remembe…
Browse files Browse the repository at this point in the history
…rs the changes to the widget values as you navigate from page to page.
  • Loading branch information
teiszler committed Oct 18, 2024
1 parent 95f71d5 commit 9b42ff0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions cnc/streamlit/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
from folium.plugins import MiniMap
from util import stream_to_dataframe, connect_redis, connect_zmq, get_drones, menu, COLORS, authenticated

if "location" not in st.session_state:
st.session_state["location"] = [40.44482669, -79.90575779]
if "map_server" not in st.session_state:
st.session_state.map_server = "Google Hybrid"
if "center" not in st.session_state:
st.session_state.center = [40.415428612484924, -79.95028831875038]
st.session_state.center = [40.413552, -79.949152]
if "tracking_selection" not in st.session_state:
st.session_state.tracking_selection = None
if "selected_drones" not in st.session_state:
Expand Down Expand Up @@ -181,24 +179,25 @@ def draw_map():

menu()


map_options = ("Google Sat", "Google Hybrid")
tiles_col = st.columns(5)
tiles_col[0].selectbox(
key="map_server",
st.session_state.map_server = tiles_col[0].selectbox(
# key="map_server",
label=":world_map: **:blue[Tile Server]**",
options=("Google Sat", "Google Hybrid"),
options=map_options,
index=map_options.index(st.session_state.map_server)
)

st.session_state.tracking_selection = tiles_col[1].selectbox(
key="drone_track",
label=":dart: **:green[Track Drone]**",
options=get_drones(),
on_change=change_center(),
index=None,
index=get_drones().index(st.session_state.tracking_selection) if st.session_state.tracking_selection else None,
placeholder="Select a drone to track...",
)

st.session_state.inactivity_time = tiles_col[2].number_input(":heartbeat: **:red[Active Threshold (min)]**", step=1, min_value=1, max_value=600000)
st.session_state.inactivity_time = tiles_col[2].number_input(":heartbeat: **:red[Active Threshold (min)]**", step=1, min_value=1, value=st.session_state.inactivity_time, max_value=600000)

if st.session_state.map_server == "Google Sat":
tileset = "https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga"
Expand All @@ -209,7 +208,7 @@ def draw_map():
name=st.session_state.map_server, tiles=tileset, attr="Google", max_zoom=20
)

st.session_state.trail_length = tiles_col[3].number_input(":straight_ruler: **:gray[Trail Length]**", step=500, min_value=500, max_value=50000)
st.session_state.trail_length = tiles_col[3].number_input(":straight_ruler: **:gray[Trail Length]**", step=500, min_value=500, max_value=2500, value=st.session_state.trail_length)

col1, col2 = st.columns([3, 1])
with col1:
Expand All @@ -219,7 +218,8 @@ def draw_map():
st.session_state.selected_drones = st.multiselect(
label=":helicopter: **:orange[Swarm Control]** :helicopter:",
options=get_drones(),
placeholder="Select one or more drones..."
placeholder="Select one or more drones...",
default=st.session_state.selected_drones
)
st.session_state.script_file = st.file_uploader(
key="flight_uploader",
Expand Down
10 changes: 5 additions & 5 deletions cnc/streamlit/pages/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ def draw_map():
#st.subheader(f":blue[Manual Control Enabled]")
st.subheader(":red[Manual Speed Controls]", divider="gray")
c1, c2 = st.columns(spec=2, gap="small")
c1.number_input(key="pitch_speed", label="Pitch %", min_value=0, max_value=100, step=5, value=st.session_state.pitch_speed, format="%d")
c2.number_input(key="thrust_speed", label="Thrust %", min_value=0, max_value=100, step=5, value=st.session_state.thrust_speed, format="%d")
st.session_state.pitch_speed = c1.number_input( label="Pitch %", min_value=0, max_value=100, step=5, value=st.session_state.pitch_speed, format="%d")
st.session_state.thrust_speed = c2.number_input( label="Thrust %", min_value=0, max_value=100, step=5, value=st.session_state.thrust_speed, format="%d")
c3, c4 = st.columns(spec=2, gap="small")
c3.number_input(key="yaw_speed", label="Yaw %", min_value=0, max_value=100, step=5, value=st.session_state.yaw_speed, format="%d")
c4.number_input(key="roll_speed", label="Roll %", min_value=0, max_value=100, step=5, value=st.session_state.roll_speed, format="%d")
st.session_state.yaw_speed = c3.number_input( label="Yaw %", min_value=0, max_value=100, step=5, value=st.session_state.yaw_speed, format="%d")
st.session_state.roll_speed = c4.number_input( label="Roll %", min_value=0, max_value=100, step=5, value=st.session_state.roll_speed, format="%d")
c5, c6 = st.columns(spec=2, gap="small")
c5.number_input(key="gimbal_speed", label="Gimbal Pitch %", min_value=0, max_value=100, step=5, value=st.session_state.gimbal_speed, format="%d")
st.session_state.gimbal_speed = c5.number_input( label="Gimbal Pitch %", min_value=0, max_value=100, step=5, value=st.session_state.gimbal_speed, format="%d")
c6.empty()

elif st.session_state.rth_sent:
Expand Down

0 comments on commit 9b42ff0

Please sign in to comment.