Custom code embed in rich text field not working

I am encountering a strange behaviour with custom code embed. The custom code embed works on a static page but does not work when it is embedded inside a rich text field.

Working example of the custom code embed on a static page:

Non-working example of the custom code embed inside a rich text field. The embed should render right below the image of the line graph:

Any ideas why this is happening?

Have a look at your console log, you’re getting an error, am5 is not defined.
My guess is you’re using it before the script that loads & defines am5.

Thanks @memetican after I fixed that I found out that I had the rich text field appearing twice on the same page for styling reasons but was causing the embed to load twice.

Fixed now.

Thanks for your help.