Dash.jl and interactive REPL?

Is there a way to have a Dash.jl application running while at the same time being able to use the REPL interactively?

Very stupid reply from me. HAve you looked at Pluto notebooks?

Thank you for the suggestion. I have no experience with Pluto. Can one mix buttons and PlotlyJs graphs?

Is your problem that Dash’s run_server function blocks the REPL which you start it from?

In that case it should be as simple as adding an @async

@async run_server(app, "0.0.0.0", 8080)
3 Likes

This is what I tried already and got the following warning.

julia> @async run_server(app, "0.0.0.0", debug=true)
┌ Warning: Hot reloading is disabled for interactive sessions. Please run your app using julia from the command line to take advantage of this feature.
└ @ Dash C:\Users\michele.zaffalon\.julia\packages\Dash\66VCI\src\server.jl:60
Task (runnable) @0x0000000057e64650[ Info: Listening on: 0.0.0.0:8050

I thought I was not using the command correctly, but now that I re-read it, I see that only the hot reloading of the Dash application is disabled.

You can, do you want it for yourself or you want to distribute it?

It is a control tool for hardware that has a long intrinsic time constant. My worry is that if I start and I get a parameter wrong, I wouldn’t be able to inspect its status.

The current debug=false Dash.jl dev mode works great, but having to run it outside the REPL means we can’t use Infiltrator.jl among other things.

So, starting from

# e.g. in MyDashApp/src/MyDashApp.jl
module MyDashApp

using Dash

function makeapp()
  app = dash()
  app.layout = #= =#
  callback!(app, #= =#)
  # ...
  return app
end

end # module

I was able to get something working with

# watch.jl
using Revise
using Dash, Dash.HTTP, Dash.Sockets
using MyDashApp

const host = "127.0.0.1"
const port = 9002

# mostly taken from
# https://github.com/plotly/Dash.jl/blob/bba2bcb8765935d5aa86660992edf275b163a741/src/server.jl#L52-L57
function start_server(app)
    handler = Dash.make_handler(app)
    server = Sockets.listen(Dash.get_inetaddr(host, port))
    task = @async HTTP.serve(handler, host, port; server, verbose=true)
    return server, task
end

function watch()
    function go()
        app = MyDashApp.makeapp()
        Dash.enable_dev_tools!(app, debug=true)
        return start_server(app)[1]
    end

    server = go()
    Revise.entr([], [MyDashApp]; postpone=true) do
        close(server)
        server = go()
    end
end

then

julia> include("watch.jl"); @async watch()

appears to work.