GenieFramework / Stipple.jl

The reactive UI library for interactive data applications with pure Julia.
MIT License
321 stars 27 forks source link

models shared by multiple routes, but not by multiple users? #128

Open honghuzi opened 2 years ago

honghuzi commented 2 years ago

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:

As mentioned by Essenciary in the Discords, these will be more easily achieved in Genie5 version. I am eager to see the coresponding demos.

hhaensel commented 2 years ago

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

essenciary commented 2 years ago

Let me try to come up with a guide/tutorial