Beni Bogosel
Beni Bogosel

Reputation: 582

Use Julia to perform computations on a webpage

I was wondering if it is possible to use Julia to perform computations on a webpage in an automated way.

For example suppose we have a 3x3 html form in which we input some numbers. These form a square matrix A, and we can find its eigenvalues in Julia pretty straightforward. I would like to use Julia to make the computation and then return the results.

In my understanding (which is limited in this direction) I guess the process should be something like:

Do you think something like this is possible? (I've seen some stuff using HttpServer which allows computation with the browser, but I'm not sure this is the right thing to use) If yes, which are the things which I need to look into? Do you have any examples of such implementations of web calculations?

Upvotes: 5

Views: 1885

Answers (3)

David P. Sanders
David P. Sanders

Reputation: 5325

Try Escher.jl. This enables you to build up the web page in Julia.

Upvotes: 0

essenciary
essenciary

Reputation: 401

Yes, it can be done with HttpServer.jl

It's pretty simple - you make a small script that starts your HttpServer, which now listens to the designated port. Part of configuring the web server is that you define some handlers (functions) that are invoked when certain events take place in your app's life cycle (new request, error, etc).

Here's a very simple official example: https://github.com/JuliaWeb/HttpServer.jl/blob/master/examples/fibonacci.jl

However, things can get complex fast:

  1. you already need to perform 2 actions:

a. render your HTML page where you take the user input (by default)

b. render the response page as a consequence of receiving a POST request

  1. you'll need to extract the data payload coming through the form. Data sent via GET is easy to reach, data sent via POST not so much.

  2. if you expose this to users you need to setup some failsafe measures to respawn your server script - otherwise it might just crash and exit.

  3. if you open your script to the world you must make sure that it's not vulnerable to attacks - you don't want to empower a hacker to execute random Julia code on your server or access your DB.

So for basic usage on a small case, yes, HttpServer.jl should be enough.

If however you expect a bigger project, you can give Genie a try (https://github.com/essenciary/Genie.jl). It's still work in progress but it handles most of the low level work allowing developers to focus on the specific app logic, rather than on the transport layer (Genie's author here, btw).

If you get stuck there's GitHub issues and a Gitter channel.

Upvotes: 0

ARM
ARM

Reputation: 1550

If you are using or can use Node.js, you can use node-julia. It has some limitations, but should work fine for this.

Coincidentally, I was already mostly done with putting together an example that does this. A rough mockup is available here, which uses express to serve the pages and plotly to display results (among other node modules).

Another option would be to write the server itself in Julia using Mux.jl and skip server-side javascript entirely.

Upvotes: 6

Related Questions