Hi, all!
I am making a web-based monitoring app using Genie and Stipple.jl.
If an action or a function is triggered by @onchange, it does not persist after refreshing on web browser.
Here’s an MWE.
module App
using GenieFramework
@genietools
# global variable for status save
gen_on = false
@app begin
@in mybutton = gen_on
@out ranval = 0.
@onchange mybutton begin
if mybutton
global gen_on = true
@info "Generation starts!"
@async begin
while gen_on
ranval = rand()
sleep(1)
end
end
else
global gen_on = false
@info "Generation stops!"
end
end
end
function ui()
[
cell([
btn("Generate random number!", @click("mybutton = !mybutton"))
])
cell([
bignumber("Random value!", :ranval)
])
]
end
@page("/", ui)
end
In this code, clicking the button will trigger a while loop generating a random number per sec.
Once I click refresh button on the browser, the value will be no longer changed even though the while loop is still running. I have to click the button twice to see the generation again. It makes sense @onchange
macro only senses the change of the value, and definitely no change has been made on mybutton
after refresh…
Then, how can I change the code so that the random number generation will be displayed after refresh? As you can see above, my trial to use a global variable was not successful
Thanks for any comments!