nail
nail

Reputation: 421

How to combine javascript/react frontend and python backend?


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

Upvotes: 14

Views: 44396

Answers (2)

Arun
Arun

Reputation: 39

Check out Streamlit. It's a very good alternative to Flask /Django. I am a backend python guy and have no experience in using frontend but I was able to spin up the front end quickly with Streamlit.

Upvotes: 3

Sayydika
Sayydika

Reputation: 178

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.

Upvotes: 11

Related Questions