andfanilo / streamlit-drawable-canvas

Do you like Quick, Draw? Well what if you could train/predict doodles drawn inside Streamlit? Also draws lines, circles and boxes over background images for annotation.
https://drawable-canvas.streamlit.app/
MIT License
541 stars 83 forks source link

Bug: clearing st.session_state when height of canvas < 300 #141

Open TGiebel opened 8 months ago

TGiebel commented 8 months ago

There seems to be a a weired bug when using the st_canvas: Minimal example:


import streamlit as st
from streamlit_drawable_canvas import st_canvas

if "Foo" not in st.session_state:
    st.session_state["Foo"] = "Value"

ResCanvas = st_canvas(height=299)

print(st.session_state["Foo"])

Behavior:

When running the above code using streamlit run xxx.py it raises an KeyError: 'Foo'. This only happens for height values below 300. The code is run 4 times by streamlit and in one of the 4 runs the st.session state is empty when printed after the canvas initialization while it is not empty right before calling it. However this does not occure every time you run it but in about 3/4 of the time.

Expected behavior:

It should print the value "Value" of Foo each time with no errors.

Environment:

It can be observed on both, Ubuntu 20.04 LTS and Windows 11 Python: 3.9.17 streamlit==1.27.2 streamlit-drawable-canvas==0.9.3

If more information is needed hit me up