Hi!
I followed through the basic example of reactive UI in the GenieFramework.
The very simple webapp below is a lineage tracking app of biological samples based on lineage graph. The user writes a sample name and gets back all its parents.
The model.output
is initialized as an empty String.
The get_all_parents
function returns a Vector of names or an empty String.
When reaching to the model.output
directly and passing it to the render_output
function I’m getting the expected behavior. Unfortunately to render the whole page I need to pass through the page
function that exposes the model values through the synthax: "{{ var }}" or span("", @text(:var)).
When passing that to the render_output
I’m getting nothing.
I’ve also tried to bypass that by doing page(model, generate_interface(model))
which didn’t work also.
Just passing the output without the render_output
function is printing the array but not as I want it. example: ["name1", "name2"]
To reproduce the example, comment the include("lineage_tracking.jl")
and define the default output as output::Union{String, Vector{String}} = ["name1", "name2"], READONLY
.
I would appreciate any help with this .
"""
lineage tracking web app
"""
# packages
using Stipple, StippleUI
include("lineage_tracking.jl")
const graph_file = "lineage_graph.mg"
@vars model_vars begin
input::String = ""
output::Union{String, Vector{String}} = "", READONLY
end
function handlers(model)
on(model.input) do input
model.output[] = get_all_parents(graph_file, input)
end
return model
end
function render_output(output)
if output != ""
paragraphs = [p(elm) for elm in output]
else
paragraphs = ""
end
return paragraphs
end
function generate_interface()
# result = render_output("{{ output }}")
result = render_output(span("", @text(:output)))
ui = row(
cell(class = "st-module", [
h1("Lineage Tracking")
textfield(class = "q-my-md", "Sample name", :input, hint = "Enter Sample name to compute lineage", @on("keyup.enter", "process = true"))
card(class = "q-my-md", [
card_section(h2("Result"))
card_section(result)
])
])
)
return ui
end
route("/") do
model = model_vars |> init |> handlers
page(model, generate_interface()) |> html
end
Genie.isrunning(:webserver) || up()