1
0
mirror of https://github.com/pyscript/pyscript.git synced 2022-05-01 19:47:48 +03:00

fix error when trying to output to non existing element

This commit is contained in:
Fabio Pliger
2022-04-18 23:10:41 -05:00
parent a6955b170a
commit 3c2ca6d68c
5 changed files with 6 additions and 6 deletions

View File

@@ -23,7 +23,7 @@
<h1>Bokeh Example</h1>
<div id="myplot"></div>
<py-script>
<py-script id="mycode">
import json
import pyodide

View File

@@ -23,7 +23,7 @@
<h1>Bokeh Example</h1>
<div id="myplot"></div>
<py-script>
<py-script id="my">
import asyncio
import json
import pyodide

View File

@@ -247,7 +247,7 @@ export class PyScript extends BaseEvalElement {
}
getSourceFromElement(): string {
return this.code;
return htmlDecode(this.code);
}
}

View File

@@ -22,6 +22,8 @@ class PyScript:
if append:
child = document.createElement('div');
element = document.querySelector(f'#{element_id}');
if not element:
return
exec_id = exec_id or element.childElementCount + 1
element_id = child.id = f"{element_id}-{exec_id}";
element.appendChild(child);
@@ -34,11 +36,9 @@ class PyScript:
img_str = 'data:image/png;base64,' + base64.b64encode(buf.read()).decode('UTF-8')
document.getElementById(element_id).innerHTML = f'<div><img id="plt" src="{img_str}"/></div>'
elif hasattr(value, "startswith") and value.startswith("data:image"):
console.log(f"DATA/IMAGE: {value}")
document.getElementById(element_id).innerHTML = f'<div><img id="plt" src="{value}"/></div>'
else:
document.getElementById(element_id).innerHTML = value;
console.log(f"ELSE: {append} ==> {element_id} --> {value}")
@staticmethod
def run_until_complete(f):