2

I have a GitHub pages website on which I'd like to run commands from SciPy. The user will input three values (A, B, C), and a python code will find the optimal nontrivial values: X, Y, Z such that X^A+Y^B=Z^C holds.

Pyodide sounds like my best chance to do so. But, I am not sure how I can get input from the user and how to let Pyodide compute the optimization process to find the values of X, Y, Z.

Edit: this is possible (see the accepted answer), however, I used streamlit which was much easier to work with.

1
  • I've also added a demo deployed on github pages. check out my updated answer. Sep 12, 2020 at 22:46

2 Answers 2

2

The answer is yes. All you need to do is to include Pyodide to your web page:

<head>
  <script type="text/javascript">
    window.languagePluginUrl = 'https://pyodide-cdn2.iodide.io/v0.15.0/full/';
  </script>
  <script src="https://pyodide-cdn2.iodide.io/v0.15.0/full/pyodide.js"></script>
</head>

load required packages and, finally, run your python code

languagePluginLoader
  .then(()=>pyodide.loadPackage(['numpy', 'scipy', 'matplotlib']))
  .then(()=>{
          console.log(pyodide.runPython(`
              import sys
              sys.version
          `));
          console.log(pyodide.runPython('print(1 + 2)'));
      });

Here is the official documentation and an article about it

I also created a simple live demo

Update 1: Here is an extended demo deployed on Github pages (source code). I'm also going to write a small guide, so stay tuned.

Update 2: Here is a tutorial

-1

I'm afraid that what you're trying to do isn't possible. Github is a code repository not an IDE (Integrated Development Environment), which means that it's a storage location for code, not for executing it. You will need to create and test your script using another program and then upload (push) this script to your repository. After this, users will be able to download (clone) your repository and run it themselves. I suggest you read a Github how to (link) if you want more information on this.

To create and test your script you can either download a client such as Pycharm. Or, if you do not want to download anything, you can use Google Colab, here you can run python code online and it's possible to save your script to Github.

Note that, though it is possible to run code on Github since the introduction of Github actions, this is meant for building/testing/publishing packages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.