Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for passing functions as layout (dynamic layouts) #15

Closed
rpkyle opened this issue Apr 26, 2020 · 4 comments · Fixed by #18
Closed

Support for passing functions as layout (dynamic layouts) #15

rpkyle opened this issue Apr 26, 2020 · 4 comments · Fixed by #18
Assignees

Comments

@rpkyle
Copy link
Contributor

rpkyle commented Apr 26, 2020

As with the other implementations of Dash, Dash.jl should support passing functions (not just components) to layout. This is described in more detail (Dash for Python) in https://github.com/plotly/dash-docs/issues/172 and https://github.com/plotly/dash-docs/pull/201.

@rpkyle rpkyle changed the title Support for passing functions as layout Support for passing functions as layout (dynamic layouts) Apr 26, 2020
@rpkyle rpkyle linked a pull request May 18, 2020 that will close this issue
@rpkyle rpkyle closed this as completed May 21, 2020
@rpkyle
Copy link
Contributor Author

rpkyle commented May 21, 2020

This was resolved by #18, closing.

@alexcjohnson
Copy link
Contributor

Does this actually work the same way as in Python? What I mean is, when layout is a function in Python, every time a user requests the app index page, the layout function executes again - so in principle you can use that to refresh a database query or something.

It looks to me as though in the current Julia implementation this function is only evaluated when you start the server. Am I interpreting this correctly?

@waralex
Copy link
Collaborator

waralex commented May 21, 2020

@alexcjohnson

layout_data(layout::Component) = layout
layout_data(layout::Function) = layout()
function process_layout(request::HTTP.Request, state::HandlerState)

    return HTTP.Response(
        200,
        ["Content-Type" => "application/json"],
        body = JSON2.write(layout_data(state.app.layout))
    )
end

function layout_data have 2 overloads (methods in Julia terms) - one used if layout is a Component and another if layout is a function.

This is about precessing the layout. To be honest, I didn't really understand how layout is related to the index_page query, which generates only the basic html of the page.

@alexcjohnson
Copy link
Contributor

OK great - just wanted to check. Looks like we are indeed all set 🎉

To be honest, I didn't really understand how layout is related to the index_page query, which generates only the basic html of the page.

Yes, that's right, the layout isn't in the index page, but it only gets refreshed during the initial load sequence, via the _dash-layout request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants