Passing client side computed values to server


I am writing a custom component which integrated a third-party javascript library into Dash Python. This library has a canvasToDOM function which accepts an object with x and y number values and returns same object but with converted values. My goal is to make is possible for the server-side code to pass these coordinates into my component via a callback and then have another callback which will read the converted coordinates.

While I can easily pass input values into my custom component through a property and call the library’s conversion function in React’s componentDidUpdate function, so far I’ve been unsuccessful at returning the conversion results back to the server (either in the same property or in a separate one)

Perhaps someone can suggest something?



Welcome to the community! :slightly_smiling_face:

Can you provide a small snippet of your React component in the place where you invoke canvasToDOM and intend to update the converted coordinates (maybe componentDidUpdate is enough)?

You are probably aware of that by now, but all Dash components (in React) get a setProps prop that is used on the React side to update props.

Thank you for your kind input.

I did manage to solve this by using the setProps prop, although I had to pass it an object, not two individual variables.
It would be great if setProps were better documented on Dash docs page.

1 Like

Yes, it has to be an object, and I agree that the component boilerplate could be better documented.

Please keep asking questions about custom components in the forum, there are many experienced component developers that can help you. :slightly_smiling_face: