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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more