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!
Running the Python backend with JavaScript frontend Make sure the backend server is running by running the command python app.py in the terminal/command prompt in the backend directory. Then start the frontend web server if it is not running in the frontend directory: http-server .
Build a Simple CRUD App with Python, Flask, and React shows how to combine a Flask backend with React. Learn React app is a Git repository with a code tutorial and instructions for how to follow along, as well as exercises to ensure you are tested as you go.
export default App; Now run the Nodejs process npm run dev in one terminal and in another terminal start Reactjs using npm start simultaneously. Output: We see react output we see a button “Connect” we have to click it. Now when we see the console server-side we see that the ReactJS is connected with NodeJS.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With