feat: matplotlib support

This commit is contained in:
Timothy J. Baek
2024-05-16 22:54:37 -10:00
parent 548160c739
commit ef300248ba
15 changed files with 4361 additions and 3 deletions

View File

@@ -139,7 +139,7 @@
};
const executePython = async (code) => {
if (!code.includes('input')) {
if (!code.includes('input') && !code.includes('matplotlib')) {
executePythonAsWorker(code);
} else {
result = null;
@@ -148,6 +148,8 @@
executing = true;
document.pyodideMplTarget = document.getElementById('plt-canvas');
let pyodide = await loadPyodide({
indexURL: '/pyodide/',
stdout: (text) => {
@@ -181,7 +183,8 @@
code.includes('requests') ? 'requests' : null,
code.includes('bs4') ? 'beautifulsoup4' : null,
code.includes('numpy') ? 'numpy' : null,
code.includes('pandas') ? 'pandas' : null
code.includes('pandas') ? 'pandas' : null,
code.includes('matplotlib') ? 'matplotlib' : null
].filter(Boolean);
console.log(packages);
@@ -221,7 +224,8 @@ __builtins__.input = input`);
code.includes('requests') ? 'requests' : null,
code.includes('bs4') ? 'beautifulsoup4' : null,
code.includes('numpy') ? 'numpy' : null,
code.includes('pandas') ? 'pandas' : null
code.includes('pandas') ? 'pandas' : null,
code.includes('matplotlib') ? 'matplotlib' : null
].filter(Boolean);
const pyodideWorker = new Worker('/pyodide-worker.js');
@@ -309,5 +313,7 @@ __builtins__.input = input`);
<div class="text-sm">{stdout || stderr || result}</div>
</div>
{/if}
<div id="plt-canvas" />
</div>
{/if}