[FIXED] How to execute python scripts from react-js?

Issue

I have a use case where I need to execute a local python script from the browser and display the output returned.

I have written my web app using react-js.

My current solution is to launch a local instance of a jupyter notebook (assuming the client is already running it) and make the user execute the prefilled first cell, but I want to be able to do this directly from the browser.


Solution

web pages cannot run arbitrary OS commands (such as executing a python scripts) from the browser - due to security reasons

a server has to provide an API for the web page to call (note that Jupyter Notebook is using it's own server to execute commands specified in a browser - python code is NOT executed directly in the browser)

there are many ways how to start a python web server, I personally recommend Flask: http://flask.pocoo.org/


Update 2022: there is now a project to run Python in the browser, PyScript, which might be worth checking for some of the use cases



Answered By - Aprillion
Answer Checked By - Katrina (Python.Easybugfix Volunteer)

Related Posts

Post a Comment