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
488 stars 40 forks source link

Preserving the type of the output of callbacks #129

Open JinraeKim opened 3 years ago

JinraeKim commented 3 years ago

Hi, I'm new to Dash.jl so the terminology may be confusing.

In my case, I'd like to send a ComponentArray (exported from ComponentArrays.jl) from a callback to another callback.

I found that after passing through a callback, ComponentArray becomes a normal array (Vector). Is it possible to make Dash.jl compatible with ComponentArray or any other abstract array types?

Because of the powerful abstraction of ComponentArrary and other cool array types in Julia, preserving array type would be really helpful for dealing with data manipulation.

JinraeKim commented 3 years ago

I don't know how Dash.jl works but I guess that adding a layer only to the callbacks whose output is "shown on web" will work. Probably...?

waralex commented 3 years ago

@JinraeKim The fact is that the result of the callback turns into json and is sent to the front end (i.e. to JavaScript code). The frontend knows nothing about Julia types, and in general about backend types.

As an idea for the future development of Dash.jl maybe I will make it possible to type the input parameters of callbacks. But it will work the same way, just the json coming from the frontend will not be parsed into the default type (dict or vector), but into a custom type according to some user-defined rules. But you can do the same now inside the callback, typing will just be a convenient wrapper so that the conversion happens automatically.

alexcjohnson commented 3 years ago

Related: https://github.com/plotly/dash/pull/1784 - not merged yet, but allows keeping some type info in the front end such that when returning it to the back end in a callback that type can be reconstructed... as well as supporting alternate and possibly more efficient serializations for certain types. If you'd like to look at that implementation and comment on how to make it more useful to Julia in the future, now's the time :)