JuliaPluto / PlutoUI.jl

https://featured.plutojl.org/basic/plutoui.jl
The Unlicense
302 stars 55 forks source link

API for packages #92

Open Sov-trotter opened 3 years ago

Sov-trotter commented 3 years ago

Thanks alot to the entire Pluto team for this super awesome package ! <3

I was recently working on an issue https://github.com/Wikunia/Javis.jl/issues/208 where the challenge was to enable users to view the rendered animation frame by frame using a slider in Pluto notebooks.

The only possible workaround I was able to find was return an array of frames from the render function and iterate over those by creating a slider within the Pluto notebook. Though this needs just two more lines of code but it isn't very user friendly.

I was wondering if we could create an API that the packages could consume to facilitate the creation of such widgets from within the packages themselves. If possible I would love to work a PR that would bring this feature.

Thanks!

fonsp commented 3 years ago

Can you try to make sure that we can understand and discuss your issue without having to understand the context of what Javis is and how it works? Try to create a minimal example, without Javis, that illustrates your problem. This would also be a first step towards thinking about a general API that packages can use.

fonsp commented 3 years ago

Though my initial reaction is that the GIF in the original issue (https://github.com/Wikunia/Javis.jl/issues/208#issue-711378199) is Interact.jl, which is an interaction within a cell. This is paradigmatically different from the interactivity that you get in Pluto: interactivity between global variables defined in different cells. Interactivity within a cell is not something that Pluto can do, hence not something that we can expose API for.

The GIF that you posted here (https://github.com/Wikunia/Javis.jl/issues/208#issuecomment-807113563) looks great, and this is exactly what I would recommend!

Is the goal to just have a slider to control the animation, or is it a more general concept? If it is the former, then another suggestion is to just use HTML and JavaScript (without Julia) to implement this, e.g. https://stackoverflow.com/questions/59499604/how-to-change-the-images-based-on-the-range-slider

Also a bit a of context: the @bind feature is built-in to Pluto, PlutoUI is just a tiny package to turn Slider(1:100) into html"<input type=range min=1 max=100>", it does not contain the interactivity/reactivity mechanism itself.