plotly / Dash.jl

Dash for Julia - A Julia interface to the Dash ecosystem for creating analytic web applications in Julia. No JavaScript required.
MIT License
486 stars 41 forks source link

add index by id #203

Closed BeastyBlacksmith closed 1 year ago

BeastyBlacksmith commented 1 year ago

This adds the ability to index into DashApp, Components and collections of Components by id. Like

using Dash
myapp.app["my-id"]

This is mainly useful for testing purposes and a convenience feature.

etpinard commented 1 year ago

Hi @BeastyBlacksmith - nice to see someone making a feature PR to Dash.jl !

Does the python version of dash expose something similar from its public API or its testing API?

If so, I think we could safely merge your PR.

If not, I (not a Plotly employee, I'm just a Dash.jl user with write rights to this repo) wouldn't be comfortable making the Dash.jl API diverge from the python version of dash.

alexcjohnson commented 1 year ago

I don't think it gets a lot of use, but Python Dash does allow you to find components within any component tree by ID:

>>> from dash import html
>>> container = html.Div([html.Div(id="a"), html.Div(id="b")])
>>> container['a']
Div(id='a')

It's a little funny to me that what you have here is app[id] though, would it make sense to change to app.layout[id]?

BeastyBlacksmith commented 1 year ago

It's a little funny to me that what you have here is app[id] though, would it make sense to change to app.layout[id]?

They work both

BeastyBlacksmith commented 1 year ago

bump.

They work both

Should I add a test for this?

etpinard commented 1 year ago

Hi @BeastyBlacksmith, if you were to remove the Base.getindex(app::Dash.DashApp, id::AbstractString) method while keeping functionally for app.layout[id], I could merge this PR and include it into Dash.jl v1.3.0 that I'd like to release at some point this week.

BeastyBlacksmith commented 1 year ago

I don't think it does any harm, but I removed it.

etpinard commented 1 year ago

Thanks for the PR @BeastyBlacksmith - merging !