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

Storing several Slider(s) to variables lead to very bad reactiveness #300

Closed
s-celles opened this issue Feb 28, 2024 · 5 comments
Closed

Comments

@s-celles
Copy link

Hello,

Following issue #299 I changed my Pluto.jl notebook to store sliders into 4 variables.

See https://gist.github.com/scls19fr/1486d2732db61d81d4b0021ca5e79481

v2 is much less reactive and nearly unusable

With v2 you always need to release left button each time you are changing value.

A fix about this will be great because the v2 code writing is much more convenient (less cells)

Kind regards

@fonsp
Copy link
Member

fonsp commented Feb 29, 2024

Can you record a video that demonstrates the problem?

@fonsp
Copy link
Member

fonsp commented Feb 29, 2024

Ah I see, you case is:

bond = @bind x Slider(1:10)
md"""
Bond: $bond

Value: $x
"""

This is not supported. It's not possible to place the bond (the result of @bind x Slider(1:10)) and the bound value (x) in the same cell.

This is because moving the slider changes x, which causes cells that reference x to re-run. Re-running the md""" cell will show the new value of x, but also re-render the bond, so a new slider is created. The new slider does not have mouse focus so you can't continue sliding.

A workaround for displaying a bond and a bound value in the same cell is to use one of Pluto's built-in combined displays. The main system is in PlutoUI.ExperimentalLayout (hbox, grid, etc). You can also use a DataFrame and put the bond and bound variable in different cells.

@fonsp fonsp closed this as completed Feb 29, 2024
@s-celles
Copy link
Author

I posted for comparison a Marimo notebook with exactly same features

https://gist.github.com/scls19fr/1486d2732db61d81d4b0021ca5e79481#file-am_modulation-py

but that's life ... if I want to use Pluto.jl... I know now that I need to have more cells.

@ederag
Copy link

ederag commented Apr 23, 2024

Late to the party (just saw this issue in the release notes), but the show_value = true argument
might be of interest here, when the slider should be in the same cell as its value.
Screenshot_20240423_142918
Of course the centering is a bit off, but that would be another issue.

@fonsp
Copy link
Member

fonsp commented Apr 24, 2024

And like I mentioned, you can use ExperimentalLayout to but bonds and values together. Here is a silly example:

Schermopname.2024-04-24.om.11.49.22.mov
# ╔═╡ b4c48706-021f-11ef-1413-059aae52cfc4
using PlutoUI

# ╔═╡ d3d667e4-4e98-44d0-b1f0-cde287afe969
bond = @bind x Slider(1:100);

# ╔═╡ aed4e404-2ca3-4db2-9ac5-d9fd65dbdd98
PlutoUI.ExperimentalLayout.grid([
	bond Text("x² = $(x*x)")
	x    bond
])

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

No branches or pull requests

3 participants