Hey everyone, the Anvil folks have kindly posted another tutorial of mine, this one on integrating a Javascript library into your Anvil app. Javascript libraries are a great way to get some additional functionality with little effort, and are often a way to supplement the client-side Python’s limitations.
Thank you very much for this tutorial! It is very instructive. Yes, there are always lots of good tips in the forum as a starting point. I always start with a search.
You write that there is no certainty whether something will work in Anvil or not, and that one should ‘experiment’.
What is the best way to experiment?
Are there specific techniques you would recommend?
Are there ‘hints’ or signs that a JavaScript library might be ‘problematic’ beyond obvious aspects (e.g. specific frameworks)?
For example, I’m currently trying to integrate a JavaScript library from Syncfusion and have already got quite far. Not everything works yet, but I suspect that’s more down to me than the library…
Before I ask for advice in the forum and get on your nerves, I would like to find a solution myself first. That’s why tutorials like this one are extremely helpful. Thank you very much!
Some libraries will integrate easily, using the technique shown in the tutorial, while others (newer ones that aren’t designed for the browser) may be more problematic. I always start with the import, e.g. from anvil.js.window import Croppie
Until that works nothing else will.
ESM style Javascript modules don’t work through that style of import, though, so you have to switch to the technique shown on the docs page, e.g. anvil.js.import_from('url for the library')
Once you get the import working, often a simple print(dir(whateveryouimported)) will give you an idea what’s available to be called.
If you get a difficult library integrated, consider making a simple app as a demonstration and posting it in Show & Tell, so others can benefit from your pain.