ValueFormatter -- pass result of python function to scripts.js

I found a workaround here:

In app.layout:
html.Div(id='myVar', **{'data-label': json.dumps(myVar)}),

Where ‘myVar’ is the python variable you want to access.
Then in scripts.py:

myVar_element = document.getElementById('myVar')
const data = myVar_element.getAttribute("data-label");
const myVar = JSON.parse(data);       
console.log(myVar) 

Thanks