Skip to content

Commit fd14d0c

Browse files
committed
fix(5-min-viz): remove stale elements from previous run
remove "greyed out" plot and error messages from the previous run. to ensure only one plot or error message is shown, draw it inside a dedicated placeholder.
1 parent 7b62ce9 commit fd14d0c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pems_streamlit/src/pems_streamlit/apps/stations/app_stations.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def main():
7474

7575
station_data_button = st.button("Load Station Data", type="primary")
7676

77+
error_placeholder = st.empty()
78+
plot_placeholder = st.empty()
79+
7780
if station_data_button:
7881
error_messages = []
7982
if len(quantity) == 0 or len(quantity) > 2:
@@ -84,14 +87,16 @@ def main():
8487
error_messages.append("- Please select at least one day to proceed.")
8588
if error_messages:
8689
full_error_message = "\n".join(error_messages)
87-
st.error(full_error_message)
90+
error_placeholder.error(full_error_message)
8891
else:
8992
df_station_data = load_station_data(station)
9093
filtered_df = df_station_data[
9194
(df_station_data["SAMPLE_TIMESTAMP"].dt.day.isin(days)) & (df_station_data["LANE"].isin(lane))
9295
]
9396
filtered_df_sorted = filtered_df.sort_values(by="SAMPLE_TIMESTAMP")
94-
plot_5_min_traffic_data(filtered_df_sorted, quantity, lane)
97+
98+
fig = plot_5_min_traffic_data(filtered_df_sorted, quantity, lane)
99+
plot_placeholder.plotly_chart(fig, use_container_width=True)
95100

96101

97102
if __name__ == "__main__":

pems_streamlit/src/pems_streamlit/components/plot_5_min_traffic_data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pandas as pd
22
import plotly.graph_objs as go
3-
import streamlit as st
43

54
QUANTITY_CONFIG = {
65
"VOLUME_SUM": {"name": "Volume (veh/hr)"},
@@ -69,4 +68,4 @@ def plot_5_min_traffic_data(df_station_data: pd.DataFrame, quantities: list, lan
6968

7069
fig.update_layout(**layout_updates)
7170

72-
st.plotly_chart(fig, use_container_width=True)
71+
return fig

0 commit comments

Comments
 (0)