I’m able to perform some action when the button is pressed but not when the daterange changes:
using Stipple
using StippleUI
using StipplePlotly
using Random
palette = [
"#e61c4c",
"#004976",
"#3fa535",
"#9d9d9b",
]
@reactive mutable struct Dashboard <: ReactiveModel
daterange::R{DateRange} = DateRange(today() - Day(3), (today()))
rstring::R{String} = ""
regen::R{Bool} = false
plot_data1::R{Vector{PlotData}} = PlotData[]
plot_layout1::R{PlotLayout} = PlotLayout()
plot_data2::R{Vector{PlotData}} = [
PlotData(
x = 1:100,
y = cumsum(randn(100)),
plot = StipplePlotly.Charts.PLOT_TYPE_SCATTER,
marker = PlotDataMarker(color = palette[1]),
name = "First",
),
PlotData(
x = 1:100,
y = cumsum(randn(100)),
plot = StipplePlotly.Charts.PLOT_TYPE_SCATTER,
marker = PlotDataMarker(color = palette[2]),
name = "Second",
),
]
plot_layout2::R{PlotLayout} = PlotLayout()
end
function ui(model)
page(model, class="container", [
heading("Dashboard")
row([
cell(class="st-module", [
datepicker(:daterange, range=true, minimal=true)
]),
cell(class="st-module", [
p([
button("Action!", @click("regen = true"))
])
p([
"Output: "
span("", @text(:rstring))
])
])
])
row([
cell(class="st-module", [
h4("Some Plot")
plot(:plot_data1; layout=:plot_layout1)
]),
cell(class="st-module", [
h4("Some other Plot")
plot(:plot_data2; layout=:plot_layout2)
])
])
]
)
end
function updateData!(model::M) where {M<:ReactiveModel}
model.plot_data1[] = [
PlotData(
x = 1:100,
y = cumsum(randn(100)),
plot = StipplePlotly.Charts.PLOT_TYPE_SCATTER,
marker = PlotDataMarker(color = palette[1]),
name = "First",
),
PlotData(
x = 1:100,
y = cumsum(randn(100)),
plot = StipplePlotly.Charts.PLOT_TYPE_SCATTER,
marker = PlotDataMarker(color = palette[2]),
name = "Second",
),
]
return nothing
end
function handlers(model::M) where {M<:ReactiveModel}
on(model.daterange) do _
updateData!(model)
end
on(model.regen) do _
if (model.regen[])
updateData!(model)
model.rstring[] = Random.randstring(10)
model.regen[] = false
end
end
model
end
route("/") do
model = Dashboard |> init |> handlers
html(ui(model), context = @__MODULE__)
end
isrunning(:webserver) || up()