I want a real time dashboard and following the streamlit guide on this closely once I ran into this error. This error was not happening last spring (2024) with the same code, but is now.
I’ve read through related forum pages and have not found anything that works. By trying out various things, I am nearly certain that streamlit is trying to make brand new charts with each loop through the While True instead of just updating the data. The data updates correctly for the KPI elements… but not the plotly elements.
Might be a quick solve here - Best Practice with Streamlit elements is to assinging a key to each element, be it text, charts, or any other thing - Must give them a unite “key”. This way we ensure that no duplicate Element ID error raises ever.
In Backend - Streamlit when rendering these elements used the element key as html element ID, which cannot be duplicate. And therefore, Streamlit ensures that we do not mess it up.
I appreciate the suggestion. I had tried adding a specified key to st.ploty_chart, e.g.,
st.plotly_chart(fig_h, key=“humidity”)
but the error persists. I think this is what you are suggesting trying.
Streamlit appears to be trying to put a 2nd chart on the dashboard on the second loop through the While True…instead of just updating the existing chart.
May I take another attempt here -
Instead of while loop, does it works for your if you use st.rerun something like this -
with humid_graph:
humiddata = data[['ts','humidity']].copy()
fig_h = px.area(
humiddata,
x="ts",
y="humidity",
title="Humidity (%)")
st.plotly_chart(fig_h)
wait_time = 2 # Change to required intervals
time.sleep(wait_time)
st.rerun() # <- this is cause the whole application to reload and hence prevent any element duplication.
If @Dhruv4 's suggestion doesn’t work, you could also try putting your plotting section into a separate function and wrapping it with @fragment - and then potentially using st.rerun(scope=“fragment”) - as described here:
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.