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
563 stars 85 forks source link

Enhancement request: programmaticaly clear canva #31

Closed GregVial closed 3 years ago

GregVial commented 3 years ago

It would be great to be able to clear canva from a python command in addition to current available option using the GUI

andfanilo commented 3 years ago

Hey @GregVial! Thanks for reaching.

Sorry for the delay. We've been thinking about ways to send events to Streamlit components, to enable for example sending a clear command to the canvas without multiple reruns (example), but no solutions yet :confused: .

In the meantime, my only technique is to change the key of the component to remount it from scratch. Maybe I could implement #7 so when you need to clear canvas you just upload a blank state, would that help you?

Fanilo

GregVial commented 3 years ago

Thanks for the suggestion, and yes, implementing #7 works perfectly for me!

andfanilo commented 3 years ago

Hey @GregVial ! I did a release of Drawable Canvas 0.6.0. It contains a new "initial_drawing" argument you can use to supply your own canvas. It basically resets the canvas when you provide a new one so if you want you can supply {"random": fixed_number_to_increment, "background": "#eee"} to clean the canvas programmatically. The normal way of using it would be to save the json_data from a previous canvas and reload it through this argument. You could even edit this json to add your own objects if you are courageous. Check out https://github.com/andfanilo/streamlit-drawable-canvas-demo. Thanks for the support :)

GregVial commented 3 years ago

Excellent, wil try it ASAP. Thanks so much for taking care of that :)