How to combine javascript/react frontend and python backend?

0

Issue

I’m not quite sure if my question is a duplicate, but I wasn’t able to find something helping me in my case.

Set Up
I’ve built a frontend webpage which contains a couple of services, for example show some timeseries and other information about my system. The website is build with the react framework and so using javascript in general.
Now I want to do some calculations about the timeseries for example calculate the similarity and other features of my sensordata. For that I’m using python which offers me a lot of libraries I’ve used for a long time and are easy to use.

What I’m looking for:
I’m looking for a very simple way to call my backend-timeseries-analysis-python script from the react GUI passing some variables like the length of the series. Also I want to process the returned values and safe the current values needed for normalization (like max,min) for further calculations.

So the procedure would look like the following:

1) Type value in react frontend input box
2) react/javascript calls pythonscript/ initialize a class and passes variables to class
3) python calculates similarity of sensor data 
4) python returns similarity values to frontend and saves classes for later call
5) react displays returned values
6) react/javascript calls pythonscript
7) python compares latest data to past data and refreshs treshholds(like max, min)
8) python calculates similarity of sensor data 
9) continue.. 

Thanks for your help!

System set up

Solution

You can expose your Python scripts on a REST API which will be called by your React frontend. Database connection will be made by this API, and the response is sent to your frontend.

See Flask (very simple for small projects) or even Django to build Python APIs.

Answered By – Sayydika

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More