How can I run a python script from javascript? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
im working on a project where i have to create a gui for. The page that i'm working on has a form for user input that asks for a string. i want to take that input and send it to a python script that I have created for processing. The python script will then return a string of words to the javascript so that i can display it to the user in the webpage. Is there any way I can do so?
note: i am not an expert in programming hence please cut me some slack. it would be great if i could get a few examples as well.

You probably want to create and expose an HTTP endpoint using a Python web framework; the easiest choice would be Flask
This would require you to create a route/action view to handle POST requests using the Python script you created. You can then consume that HTTP endpoint using AJAX.
Another option would be to leverage the "serverless" infrastructure that Amazon Web Services provides; that way you could create an HTTP endpoint using Amazon API Gateway, and have that endpoint call an Amazon Lambda Python function, which would run your Python script and return the results. The advantage of this method is that is incredibly cheap and relatively easy to set up, especially if you only need to call that one Python script. Also, with this set up you wouldn't have to spin or maintain any web server yourself, since your Python script would be running directly on Amazon's servers.
Best of luck.

Related

Send data continuously from flask api to javascript frontend [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
So I want to make a website which visualize in real time some simulations which take some time to compute and I would like to know the easiest way to do it.
For now, the javascript front-end get the final result in once from the flask api and show it to the user. I would like the backend to send the result of the simulation in real-time, with batch of data at time intervals while it still computes, and the frontend to display the results in real time without having to re-load the page each time. How could I do that easily ?
Thanks
There are two common methods for doing this:
Web Sockets
Server-Sent Events (SSE)
If the frontend of your application needs to speak to the backend very often, then it would be best to open up a web socket for this channel of communication. Here is a list of popular frameworks for commonly used languages, including Python: https://github.com/facundofarias/awesome-websockets
If the frontend of your application just needs to listen for updates, then it may be better to use open up an event stream with SSE. Note that this can be done nowadays in most browsers in plain JavaScript at the frontend, but the backend may be a little more involved. Since you're using Flask, you might want to take a look at Flask-SSE.

Website building, ask server to run a script with input [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm quite a newbie in everything related to web development, but I had this project in my mind that I really wanted to realize.
At the moment I am struggling with a method to send a request to the server hosting the website. The idea is that from the site you can enter keywords, and those keywords should be run in a script (python or java(script)) on the server after which it returns an output to the webpage. In theory this script could be executed in the website itself as javascript, but I would like to use the computing power and internet access from the server.
I have researched on using Json and javascript for the job, but I think there has to be a better way for this purpose. Is there anyone that can direct me where to look?
You should build your form in HTML. (More info: https://www.w3schools.com/html/html_forms.asp)
In client-side JavaScript (the code that website users have executing in their browser), you should use the jQuery library to scoop the data out of your form. Take a look at the .submit() and .val() functions to get started. Then you can use jQuery's AJAX function to submit requests to the server-side API in a JSON format.
On the server, in addition to creating a way of serving up the webpages (with their client-side JavaScript), you will then need to create an API to receive and respond to these requests. One way to do this is by running Node.js with Express, which will allow you to write your API in JavaScript. The downside to this is you will have to pay to get a full-fledged virtualized cloud server through AWS, Rackspace, or another host. The other option is for you to write your API in PHP, which is supported by free webhosts like x10hosting.com.

How to connect html page to Marklogic Database using javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am newbie to web designing. Here I am trying to develop a web page where it prompts for username and password and when I click on button, this html has to make connection with these username and password values entered by user to Marklogic database . Could anyone please help how to do this? Is it through Javascript or PHP? If so please advise where can I find step by step explanation of this process ? Also it is okay if I get procedure for any NOSQL database.
OK. Your statement is a bit big and broad.. I decided to extract the most relevant concepts:
Sample Application including authentication
MarkLogic
Javascript or PHP
Therefore, I suggest looking at a reference framework using all javascript:
http://www.marklogic.com/what-is-marklogic/whats-new/samplestack/
This can have a node.js middle tier in node.js and does not require java.
It is a big step forward and (sort of) complex, but it is a complete example.
If it is too much for what you are looking for, then I suggest you research more specifically what you need in these two specific items in MarkLogic documents:
HTTP Server (where you can run your HTML/CSS/Javascript from)
REST API (for which you can use against your js code)
This is a 2-tier approach where your application(HTTP) server is serving both your HTTP site as well s the default REST enpoints.

create PDF file in JS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am developing a web application using client side MVC. The technology stack is Backbone JS, HTML5 and Spring at the Server side.
I have a requirement where I do some data manipulation at the client side using Javascript by using JSON files as the data payload kept on the web server directly. This is a high traffic part of the app and I don't want to hit my app server for such siple data manipulations.
Now on the same module - I have a requirement where I need to generate a PDF file which effectively contains a static template and then I need to fill the template using effectively the same data that I already have at client side. I need to generate the PDF and let the user download it.
Any idea how can I acheive it completely at the client side in a clean and robust way.
From what I understand is you have an html template that you want to fill with certain data and then render it as a pdf?
For client side, have tried looking at something like jsPdf (http://parall.ax/products/jspdf)? The html renderer is still in early stages but it seems to work decently.
As Bogdan pointed out, a backend solution is also possible. You could look at pd4ml (http://pd4ml.com/) or even call into something like pandoc (http://johnmacfarlane.net/pandoc/) or even phantomjs (http://phantomjs.org/) to perform the conversion and then pass the generated pdf back to the client.
If it is not an html template, I am sure a number of the above solution should work regardless.

Build website using JSP or Javascript [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have to build a website which involve e-commerce stuff like it should allow the users to login and then view the available items. Once the user selects the items and makes payment, it may need additional information in the form of some images/videos to complete the order. So, after payment step, it prompts the user to upload the file and when the file is uploaded on the server, request is complete and the user is kept informed about the status.
All the core functionality is already implemented using REST-ful webservices. I am not able to decide if I should implement the website using HTML+JS (using AJAX to call webservices) or should still use JSP and call webservices using java at server side? Someone suggested me that using JSP is better since it will execute on server side and hence will be secured and faster. But, I somehow feel that HTML+JS is easier to go. Is there some specific advantage to use a server side script like JSP for this purpose? Any ideas are most welcome.
Yes server side scripting will be fruitful for this purpose for security constraints. Or you can use angular js though they are easy to learn and they are secure and can make fast XHR request response. :)

Categories

Resources