Stipple.jl
Stipple.jl copied to clipboard
models shared by multiple routes, but not by multiple users?
Hello everyone, I am building my own web app with Stipple.jl. I am struggling now on uploading files. I followed the demo in https://github.com/GenieFramework/StippleDemos/blob/master/BasicExamples/CsvUpload/CSVUpload.jl and wrote my own CSV uploader. The problem is, I'd assign the DataFrames extrated from uploaded file to the main ReactiveModel just created. I just don't know how to achieve this. If that is impossible, should i use global variables instead?
below are the codes
@reactive mutable struct MyModel <: ReactiveModel
df::R{DataFrame} = DataFrame("x" => [0.0, 1000.0], "y" => [0.0, 1000.0])
end
model = init(MyModel, debounce = 0)
route("/upload_ovl", method = POST) do
files = Genie.Requests.filespayload()
for f in files
@time df = XLSX.readtable(f[2].name) |> DataFrame
@info "Uploading: " * f[2].name
model.df[] = df
end
"pass"
end
route("/") do
model |> handlers |> ui |> html
end
The features I need are:
- share model among different routes, so that I can modify model.df[] in the upload method
- do not share same model among different users, so that the modification of model.df[] won't take effect for different user.
As mentioned by Essenciary in the Discords, these will be more easily achieved in Genie5 version. I am eager to see the coresponding demos.
I think, you would need to store the session id in a private field of the model, e.g. id__.
Then you can read the session I'd in the routine of your upload route and store the file in a session-specific directory
Let me try to come up with a guide/tutorial