Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canvas result clear automatically #84

Open
kjlee18 opened this issue Aug 2, 2022 · 3 comments
Open

canvas result clear automatically #84

kjlee18 opened this issue Aug 2, 2022 · 3 comments

Comments

@kjlee18
Copy link

kjlee18 commented Aug 2, 2022

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
Copy link
Contributor

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:

  • a handler that is called whenever the user finishes drawing the rectangle (and not in intermediate rectangle positions during the drawing phase), and
  • a way to clear the canvas programmatically from python

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

@andfanilo
Copy link
Owner

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 (streamlit/streamlit#3977)

@nazli-samsung
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants