Hello,
I am new to streamlit and coding in general and Iām working on a custom app to display some of our organizationās data. The app Iāve created works, but it is very slow and zooming in and out and other interactive features are very time consuming. I think this can be solved with caching but Iām not sure how to integrate that into my current app. Any help would be great!
import streamlit as st
import altair as alt
import pandas as pd
import erddapy
from vega_datasets import data
Connect to ERDDAP
st.title(āSWOT Prawler Dataā)
e = erddapy.ERDDAP(āhttp://heron.pmel.noaa.gov:8080/erddapā, protocol=ātabledapā)
e.dataset_id = āTELON001_PRAWC_N001ā # Data Set to Use
Pull Data from ERDDAP
dfp = e.to_pandas()
dfp[ātime (UTC)ā] = pd.to_datetime(dfp[ātime (UTC)ā])
Create a subset of the datas
sub = dfp.loc[:,[ātime (UTC)ā, āSB_Depthā, āSB_Tempā, āSB_Conductivityā, āwetlab_Chlorophyllā]]
source = sub
brush = alt.selection(type=āintervalā)
#dropdown to select y-axis
option = st.selectbox(
āSelect a Datasetā,
[āSB_Temp:Qā, āSB_Conductivity:Qā, āOptode_Dissolved_O2:Oā, āwetlab_Chlorophyll:Qā])
#top panel to plot the data
c = alt.Chart(
source,
title=āSWOT Prawler Dataā
).mark_circle(size=30).encode(
x=alt.X(ātime (UTC):Tā, scale=alt.Scale(
clamp=True, padding=10)
),
y=alt.Y(āSB_Depth:Qā,axis=alt.Axis(title=āDepth (m)ā),
scale=alt.Scale(zero=False, padding=5, domain=[500,0])),
color=alt.condition(brush, option, alt.value(ālightgrayā))
).add_selection(
brush
).properties(
width=700,
height=300
)
#2nd chart
second = alt.Chart(
source,
title=āZoomed in Plotā
).mark_circle(size=30).encode(
y=alt.Y(āSB_Depth:Qā, sort = ādescendingā),
color=alt.Color(option, sort = ādescendingā, scale=alt.Scale(scheme=āredblueā)),
x='time (UTC):T',
tooltip=[
alt.Tooltip('time (UTC):O', title='Datetime'),
alt.Tooltip('SB_Depth:O', title='Depth'),
alt.Tooltip(option, title=option)
]
).transform_filter(
brush
).properties(
height=500, width=700
).interactive()
c & second