Embed a Dash app in Genie.jl website

Hi!

I’m trying to embed a Dash.jl app in a website that is generated by Genie.jl.

My approach is working with Stipple.jl apps but unfortunately, due to the lack of documentation I’m not able to do something useful with it :confounded:. This is why I want to use Dash.jl.

My approach with Stipple.jl is as follows:

In the MyController.jl file I have a slightly modified version of the HelloStipple example

# MyController.jl
module MyController

using Genie, Genie.Renderer.Html, Stipple

Base.@kwdef mutable struct Name <: ReactiveModel
  name::R{String} = "World!"
end

global MODEL = Stipple.init(Name())

function ui()
  [
    page(
      vm(MODEL), class="container", title="Hello Stipple",
      [
        h1([
          "Hello, "
          span("", @text(:name))
        ])

        p([
          "What is your name? "
          input("", placeholder="Type your name", @bind(:name))
        ])
      ]
    )
  ] |> html
end

function _ui() 
  html_str = String(ui().body)
  html(:scales, :ui; ui=html_str)
end

end

With the _ui() function I send the HTML string to the view file in resourches/my/views/ui.jl.html which simply looks like this:

<% ui %>

And for completeness the routes.jl file:

# routes.jl
using Genie.Router, MyController

route("/", MyController._ui)

Now I suppose to make it work with Dash.jl I have to somehow get the proper HTML string from my app. The problem is I can’t figure out how to do this. Searching for how to embed a Dash app into a website I found this solution for Python/Flask:

server = Flask(__name__)
app = dash.Dash(__name__, server=server, url_base_pathname='/dummypath')
app.layout = <setup your Dash app here>

@server.route("/dash")
def MyDashApp():
    return app.index()

So, if I interpret that correctly, app.index() returns the HTML in this case. Problem is, I can’t find a Julia equivalent to the app.index() method.

1 Like

Why do you want Dash.jl in a Genie.jl website? It’s not a requirement for Dash at least, nor am I sure it’s supported (by either). Generally Julia packages compose very well, so I’m a bit curious if it works here too, but Dash already has Flask-equivalent component dependency, so I’m just pointing out in case you’re on the wrong path.