Adding your Julia code
Newly created apps, consist of just two files: app.jl
and app.jl.html
. app.jl
is the entry point to the app, and any code in it will be executed. This is also where you'll write the app's logic, which is the code that manages the interaction between the Julia code and the web UI. Then, app.jl.html
contains the UI generated by Genie Builder.
To add your Julia code, there are two possibilities:
- Writing it in
app.jl
. - Writing it in a separate file and importing it into
app.jl
.
Choosing one or another depends on the complexity, scale and organization of your code.
Writing Julia code in app.jl
The default app.jl
comes populated with
- The import of the
GenieFramework
package. - A block delimited by the
@handlers
macro, which is where later on you'll add reactive code to handle user interaction. - A call to the
@page
macro to render the UI.
Your code, with all the function and object definitions, should be placed between the package imports and the @handlers
macro as in the example below.
module App
using StatsBase: mean, std, var
using GenieFramework
@genietools
function statistics(x)
mean(x), std(x), var(x)
end
@app begin
# reactive code goes here
end
@page("/", "app.jl.html")
end
Writing Julia code in separate files
For easier debugging and better organization, it is best to put your analysis code in a separate file. In order to call a piece of code from app.jl
, the corresponding file must be imported first with include
. Moreover, it is recommended that the code is wrapped into a module to avoid conflicts with the app's logic.
module App
include("stats.jl")
using .Stats
using GenieFramework
@genietools
@app begin
# reactive code goes here
end
@page("/", "app.jl.html")
end