Good day to you,
I was previously running Streamlit 1.49.1 locally using Plotly to display multiple charts\graphs from real-time data stream updating every 250 milliseconds. While using Plotly, whenever the chart would render, it would cause the screen to scroll up to the top of the page and flash, making all content below the chart effectively unreachable, as the page content scrolls up frequently. After trying a number things without success, such as trying to affect the scrollbar, I searched the forums and found this a repeated issue that has not been addressed.
The below is NOT my code but code from @poilkj09862 who has the same issue.
After reading this post, I reverted to streamlit 1.34.0 as a member offered a mitigation and the problem went away. That reversion prevents me from using newer widgets and updated code BUT the debilitating scrolling of the chart\page is mitigated.
Please advise.
Thank you.
import streamlit as st
import plotly.graph_objects as go
import pandas as pd
import numpy as np
import time
from streamlit import session_state as stss
center_freq = ['20', '25', '31.5', '40', '50', '63', '80', '100', '125', '160', '200', '250', '315', \
'400', '500', '630', '800', '1 k', '1.25 k', '1.6 k', '2 k', '2.5 k', '3.15 k','4 k', '5 k', '6.3 k', '8 k', '10 k', '12.5 k', '16 k', '20 k']
if "a" not in stss:
stss.a = pd.DataFrame(np.random.rand(60)*100, columns=['r_value'])
stss.a['x'] = np.arange(60)
if "b" not in stss:
stss.b = pd.DataFrame(np.random.rand(len(center_freq))*50, columns=['r_value'])
stss.b['x'] = np.arange(len(center_freq))
if "fig1" not in stss:
stss.fig1 = go.FigureWidget(go.Scatter())
stss.fig1.update_layout(
title=f"Real-Time data",
xaxis_title="Time Stamp",
yaxis_title="Data",
)
if "fig2" not in stss:
stss.fig2 = go.FigureWidget(go.Bar())
stss.fig2.update_layout(
title=f"One Third Octave Band",
xaxis_title="Frequency Band",
yaxis_title="PSD",
)
def main():
st.set_page_config()
# creating a single-element container.
st.title("Test")
placeholder1 = st.plotly_chart(stss.fig1)
placeholder2 = st.plotly_chart(stss.fig2)
while True:
stss.a['r_value'] = np.random.rand(60)*100
stss.b['r_value'] = np.random.rand(len(center_freq))*50
with placeholder1.container():
stss.fig1.data[0].x = stss.a["x"]
stss.fig1.data[0].y = stss.a["r_value"]
st.plotly_chart(stss.fig1)
with placeholder2.container():
stss.fig2.data[0].x = stss.b["x"]
stss.fig2.data[0].y = stss.b["r_value"]
stss.fig2.update_xaxes(
tickmode="array",
tickvals=stss.b.index,
ticktext=center_freq,
tickangle=-45,
title_text="Frequency Band",
title_font=dict(size=12)
)
st.plotly_chart(stss.fig2)
time.sleep(1)
if __name__ == '__main__':
main()