Import external js library to kotlin project

Hello everyone,

I’m super new to Kotlin and I’m trying to write some interactive demo using Kotlin with D3.js. Although it is straightforward to use jQuery in Kotlin, I am not sure how to manually include a 3rd party JS file and call it in .kt. I want to do all my logic (data preprocessing) in Kotlin and then call some D3.js function to visualize the processed data objects in Kotlin.

Any thoughts and inputs/demos are appreciated, thanks!

1 Like

It’s easy to call JS libraries from Kotlin. What you need to do is:

  1. In any .kt file, declare what the Kotlin signature of the JS function is, and prefix it with @native.
  2. Add the .js file in the html.
  3. Call the function.