Published
Edited
Apr 15, 2020
2 forks
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//js from Brython with PN lib source from part of notebook
// https://github.com/brython-dev/brython/issues/1055#issuecomment-472862271
//runBrython(code) from Bryan Gin-ge Chen https://observablehq.com/d/9264b6145e1b1e1c
//as tagged template literals
//Optional python source (libPyStr) can be added at the beginning in another tagged template literals (ex. pyPN)
function py(brythonSrc, libPyStr){//libPyStr:string, brythonSrc = Array [ "x=5\nprint(f'x=\n{x}')\n" ]
var raw = (libPyStr ? libPyStr+'\n' : '')
+ brythonSrc.raw.join('') //x=5
//print(f'x=\n{x}')
//
// https://talk.observablehq.com/t/execute-code-in-non-strict-mode/1728
// https://observablehq.com/@mootari/tracking-and-displaying-errors
try {
var br_js = (1,eval)(__BRYTHON__.python_to_js(raw))
} catch(err) {
err.message = err.args
console.error(err.message)
throw err
}
return br_js
} //DO NOT USE ${ INSIDE brythonSrc !
Insert cell
// tagged template literals with python source (lib) added at the beginning
function pyPN(brythonSrc){//brythonSrc = Array [ "x=5\nprint(f'x=\n{x}')\n" ]
return py (brythonSrc, PNlibSrc.innerText)
} //DO NOT USE ${ INSIDE brythonSrc !
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more