Last active
          March 5, 2021 13:56 
        
      - 
      
- 
        Save kapulkin/d79ed647fc075b14b9cd4ca67cc657bb to your computer and use it in GitHub Desktop. 
Revisions
- 
        kapulkin revised this gist Nov 8, 2019 . 2 changed files with 10 additions and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,13 @@ pyodide.loadPackage(['numpy']).then(() => { const el = document.getElementById("pyodide") pyodide.runPython( `import numpy as np import pyodide data = pyodide.open_url("${fileUrl}") x = np.genfromtxt(data, delimiter=",") dataList=(-x).tolist()`) const data = pyodide.pyimport("dataList") el.textContent = data console.log(data) }) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ 1725, 1747 1753, 1775 1007, 1029 
- 
        kapulkin revised this gist Nov 8, 2019 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,8 +18,6 @@ } } function handleFiles (files) { const file = files[0] const fileUrl = createObjectURL(file) 
- 
        kapulkin created this gist Nov 7, 2019 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ <html> <head> </head> <input type="file" id="fileInput" onchange="handleFiles(this.files)"/> <div id="pyodide"/> <body> <script type="text/javascript"> self.languagePluginUrl = "/python/" function createObjectURL ( file ) { if ( window.webkitURL ) { return window.webkitURL.createObjectURL( file ); } else if ( window.URL && window.URL.createObjectURL ) { return window.URL.createObjectURL( file ); } else { return null; } } let dataForPython function handleFiles (files) { const file = files[0] const fileUrl = createObjectURL(file) console.log(fileUrl) downloadPyodide(function () { const el = document.getElementById("pyodide") console.log('py') el.textContent = pyodide.runPython('import sys\nsys.version') pyodide.loadPackage(['numpy']).then(() => { const el = document.getElementById("pyodide") const data = pyodide.runPython(`import numpy as np\nimport pyodide\ndata = pyodide.open_url("${fileUrl}").read()\nnp.array(data).tolist()`) el.textContent = data console.log(data) }) }) } function downloadPyodide (callback) { const onScriptLoad = function () { languagePluginLoader.then(function () { callback(pyodide) }) } const scriptElement = document.createElement('script') scriptElement.type = 'text/javascript' scriptElement.src = '/python/pyodide.js' scriptElement.onreadystatechange = onScriptLoad scriptElement.onload = onScriptLoad document.head.appendChild(scriptElement) } </script> </body> </html>