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
544 stars 83 forks source link

canvas result clear automatically #84

Open kjlee18 opened 1 year ago

kjlee18 commented 1 year ago

Hi, thanks for your work. Streamlit is my first web-tool for visualize and I am using canvas module for interaction.

I am using st_canvas in freedraw and circlemode to get mouse click as stroke or circle While, getting interactions I want to clear the past strokes and leave only latest strokes (e.g. 3) I know that clear function can be done online by clicking the trash bin button, but is it possible to handle it automatically on python code?

image

I want to clear 3 points from the image automatically

andreaferretti commented 1 year ago

I have a similar issue. I would like to draw a rectangle to select a region in an image to zoom. Hence, I would like for the user to be able to draw a rectangle, then, when the mouse is up, get the rectangle coordinates and clear the rectangle.

For this, I would need:

I am not sure what the optimal API would be. Is there a way to do this?

andfanilo commented 1 year ago

Hello, I'm so sorry for being late, Github did not correctly surface your comments... For now, a bruteforce, not very cool approach would be to manually save the state of the drawing from 3 versions ago, and restart the canvas by changing the key argument and reinject it through initial_drawing

Adding a programmatic way of clearing from Python is...not really possible sadly because of the way Streamlit Components are structured :( you can't send signals to a component from Python or something like a callback (https://github.com/streamlit/streamlit/issues/3977)

nazli-samsung commented 1 year ago

Hello,

Many thanks for this useful component. I'm also trying something similar but have been unsuccessful, so far. I have a canvas which is being rendered after a text_input component. I want to modify the text_input string based on the drawing in the canvas following some rules. I think what I am after is an on_change callback for the drawable_canvas component. From the responses above this seems undoable but I was wondering whether you have a way around this, many thanks.