Make a webapp framework/ecosystem as awesome as R's Shiny: a challenge to Julia's community

In 2019, Julia 1.x world, I found the combination of Intract+Mux relatively simply for deploying an interacting model to the web à-la Shiny, although the documentation of the two cited packages could still be improved…

using Interact,Plots,Mux

function myModel(p1,p2)
    xrange = collect(-50:+50)
    model = p1.*xrange .+ p2.* (xrange) .^2
    return model
end

function createLayout()
  p1s = slider(-50:50, label = "Par#1 (linear term):", value = 1)
  p2s = slider(-5:0.1:5, label = "Par#2 (quad term):", value = 1)

  mOutput = Interact.@map myModel(&p1s,&p2s)
  plt = Interact.@map plot(collect(-50:50),&mOutput, label="Model output")
  wdg = Widget(["p1" => p1s, "p2" => p2s], output = mOutput)
  @layout! wdg hbox(plt, vbox(:p1, :p2))
end

function serveLayout(port)
    try
      WebIO.webio_serve(page("/", req -> createLayout()), port)
    catch e
      if isa(e, IOError)
        # sleep and then try again
        sleep(0.1)
        serveLayout(port)
      else
        throw(e)
      end
    end
end

serveLayout(8001)

Resulting in:

Disclaimer: the code in this example is from an upcoming Apress book on Julia I am finalising… I am a bit confusing on copyrights, but I think I can still post it…

20 Likes