Hello @Alexander_Hexemer, responded on the GIthub issue but maybe that could help others:
Under the hood, json_data is a FabricJS object exported in JSON with .toObject.
It seems for a scaled object, you will need to apply the scaleX/scaleY factor to the height/width to retrieve the correct values. FabricJS preserves the original dimensions and applies a ratio independently.
After playing around with this a while, Iām still trying to figure out if there is a way to pass drawings to the canvas or load a state from Streamlit? Has anyone had any success with this?
Hi im not that familiar with the component yet but id like to know if it is possible to have a jpg as background picture so u can draw above it. oh wait i just found it.
With a SVG path library like svgpathtools, you can load and manipulate the paths you draw on the canvas. For example you can compute the length in pixels of any drawn arc on the canvas!
Hey there!
It seems like something happened to the Streamlit Drawable Canvas code today. I use streamlit-drawable-canvas for educational purposes.
Earlier today, the canvas was working for my program (itās been working perfectly fine for the past several months). I define the canvas as follows:
canvas_result = st_canvas(
fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
stroke_width=stroke_width,
stroke_color=stroke_color,
background_color= bg_color,
# background_image=Image.open(bg_image) if bg_image else None,
update_streamlit=realtime_update,
width = 500,
height= 500,
drawing_mode=drawing_mode,
key="canvas",
)
and then this afternoon, I get this error:
2021-07-01 23:00:34.341 Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/streamlit/script_runner.py", line 349, in _run_script
exec(code, module.__dict__)
File "/content/app.py", line 37, in <module>
key="canvas"
File "/usr/local/lib/python3.7/dist-packages/streamlit_drawable_canvas/__init__.py", line 138, in st_canvas
w = component_value["width"]
TypeError: string indices must be integers
Do you know if any updates might have caused this? I havenāt touched this code in a while and then it broke.
If possible could we continue the discussion there ? Most notably Iād love to know your version of streamlit-drawable-canvas, if you made a recent upgrade and if it works again by downgrading.
Hey everyone, this should be fixed with Streamlit 0.84.1 streamlit/streamlit#3507 (comment). Iāve tested on the demo app and it works well, so it should work on your side too!
Hey @andfanilo
I have a small issue I m trying to draw a polygon and use it as the ROI for detections in a video but I am not sure how exactly can I extract the points from the table as I am getting the following error
for this code st.dataframe(pd.json_normalize(canvas_result.json_data["objects"])) in drawing a polygon
ArrowTypeError: ("Expected bytes, got a 'int' object", 'Conversion failed for column path with type object')
TypeError: a bytes-like object is required, not āCanvasResultā
I am using 0.88 version
# Create a canvas component
image_data = st_canvas(
b_width, b_color, bg_color, height=150, drawing_mode=drawing_mode, key="canvas"
)
# Do something interesting with the image data
if image_data is not None:
st.image(image_data)
I have a small issue I m trying to draw a polygon and use it as the ROI for detections in a video but I am not sure how exactly can I extract the points from the table as I am getting the following error for this code st.dataframe(pd.json_normalize(canvas_result.json_data["objects"])) in drawing a polygon ArrowTypeError: ("Expected bytes, got a 'int' object", 'Conversion failed for column path with type object')
I think the explanation is https://discuss.streamlit.io/t/all-in-on-apache-arrow/15342/3:
if canvas_result.json_data is not None:
objects = pd.json_normalize(canvas_result.json_data["objects"])
for col in objects.select_dtypes(include=['object']).columns:
objects[col] = objects[col].astype("str")
st.dataframe(objects)
or change the serialization from arrow to legacy, by putting in .streamlit/config.toml the following:
[global]
dataFrameSerialization = "legacy"
@BeyondMyself the image is stored in image_data.image_data, the image_data variable contains 2 properties: image_data for the image and json_data for the canvas JSON representation.
Are you using this locally or on the demo app (https://share.streamlit.io/andfanilo/streamlit-drawable-canvas-demo/master/app.py)? Every drawing executes a full Streamlit script rerun which on larger apps can take some time depending on the specs of your machine (I see about half the lag on Streamlit Cloud and a third of the lag on my personal machine). You can disable the Streamlit rerun for every stroke by passing update_streamlit=False and updating by pushing the arrow in the toolbar if the lag really puts you off (actually you could even run custom code with Session State to pass update_streamlit to True every 5-10 strokes if you want).
Also right now I donāt know how exactly I could optimize the code more, maybe thereās an iframe remounting I can optimize or some other advanced React useEffect that is not well implemented, but Iād need to dig deep which I wonāt be able to do immediately
Hi man, thank you for your awesome work!
When Iām trying to run your default demo code, I got exception info like this: StreamlitAPIException : (āExpected bytes, got a āfloatā objectā, āConversion failed for column path with type objectā)
and it occurred here:
st.dataframe(pd.json_normalize(canvas_result.json_data[āobjectsā]))
Plus, when I uncheck update in realtime, thereās no button called āsend to streamlitā.
Can you take a look?
Btw, Iām using Steamlit 1.1.0
On the StreamlitAPIException, I think the correct code is
if canvas_result.json_data is not None:
objects = pd.json_normalize(canvas_result.json_data["objects"]) # need to convert obj to str because PyArrow
for col in objects.select_dtypes(include=['object']).columns:
objects[col] = objects[col].astype("str")
st.dataframe(objects)
because Streamlit uses Arrow to serialize dataframes, everything has to be cast out of objects. Is there a location I forgot to change this?
For the update in realtime part, the button is circled in red in the following
Do tell me if you have a better idea for a clearer icon
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking āAccept allā, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.