Components keep refreshing/remounting when in a column
See original GitHub issueSummary
With or without a key
, a component in a column will eventually refresh/remount, sometimes lock itself into a refresh loop.
Not sure but seems to depend on the browser (Chrome/Edge stop refreshing at some point but if you interact with the component it goes off again. Firefox stays in loop forever).
Steps to reproduce
Using drawable canvas
Canvas won’t stop remounting.
https://github.com/andfanilo/streamlit-drawable-canvas/issues/23
import streamlit as st
from streamlit_drawable_canvas import st_canvas
col1, col2 = st.beta_columns(2)
with col1:
canvas_image = st_canvas(
fill_color = "rgba(255, 165, 0, 0.3)",
stroke_width = 2,
stroke_color = '#e00',
drawing_mode = "line",
key = "canvas",
)
with col2:
options = ['U','D','R', 'L']
lines = [st.selectbox('Select', options, key=x) for x in range(4)]
Using component template
Component will stop at state 1.
if not _RELEASE:
import streamlit as st
col1, col2 = st.beta_columns(2)
with col1:
st.subheader("Component with constant args")
num_clicks = my_component("World")
st.markdown("You've clicked %s times!" % int(num_clicks))
with col2:
st.subheader("Component with variable args")
name_input = st.text_input("Enter a name", value="Streamlit")
num_clicks = my_component(name_input, key="foo")
st.markdown("You've clicked %s times!" % int(num_clicks))
Expected behavior:
If there’s a key, no remount. If there’s no key, as usual.
Actual behavior:
Is this a regression?
Using the drawable canvas example, I went back to the beta builds @akrolsmir ✔️ Works on streamlit-0.65.24-py2.py3-none-any.whl 🟥 Doesn’t work on streamlit-0.66.22-py2.py3-none-any.whl
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:16 (4 by maintainers)
Top Results From Across the Web
Streamlit Refresh Page - MS-PrintdeSign
Components keep refreshing/remounting when in a column #2145. import streamlit as st class NewStudent(): def __init__(self, page_id): st.
Read more >Why my component column do not highlight? - Stack Overflow
A TableModel should NOT store a component as data. A model should store data and then renderer the data. If you want to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah, so I’m not sure I understood everything without seeing your code 😃 and I have not tested the following hypothesis, but I fear if you write
useEffect(() => Streamlit.setComponentValue(42))
then anytime the component renders, it will call theuseEffect
which will callStreamlit.setComponentValue
and that would run a rerender of the component (becauseStreamlit.setComponentValue
reruns the Streamlit script and rerender all components on the page). If it rerenders then it’s going to run theuseEffect
again, which will retrigger a rerender and then you’re going into an infinite loop of refreshing.If you place the
setComponentValue
inhandleSelected
then pass it toonSelected={handleSelected}
in Plotly, then it will only be run when interacting with Plotly, not whenever the component rerenders, so you don’t get the infinite refresh.Hope I got it on point 😃
Fanilo
First test on Drawable Canvas on streamlit-nightly LGTM !