@bind input element generator? #923
-
Hi all, Is there a way to iteratively generate Pluto I've looked around and can't find this issue addressed quite yet. If I've missed something please let me know. For example, it would be nice to be able to do something like the following: vec = [1,2,3]
md"""
join( [ "\$(@bind var$i CheckBox()" for i in vec ], " | ")
""" to produce the markdown: md"""
$(@bind var1 CheckBox()) | $(@bind var2 CheckBox()) | $(@bind var3 CheckBox())
""" ...and have it actually interpolate into a cell correctly. Important to note that the length and contents of vec may vary (in a sensible way). Trying this general approach hasn't been fruitful and I'm hoping there is a more workable / elegant approach? It also seems that the ability to programmatically create UI elements (generating a drop-down menu for each column in a dataframe, for example) would be a prerequisite towards #664. Thanks for any help! :) |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 4 replies
-
Hey! I think that this would be a cool feature (will take some work to implement), but in the meantime we can do this on the frontend side. You could write a javascript widget that displays N numberfields, and the bound value is the array of those values. I did something similar here: https://github.com/fonsp/disorganised-mess/blob/master/confirm%20combine.jl |
Beta Was this translation helpful? Give feedback.
-
This example doesn't work for me ( I tried this instead
but it doesn't work: the |
Beta Was this translation helpful? Give feedback.
-
With the newly added macro support in version The code for the notebook is here. |
Beta Was this translation helpful? Give feedback.
-
That's neat, but I'm not sure it solves the original issue.
|
Beta Was this translation helpful? Give feedback.
-
Just adding a link here with further discussion happening on Zulip right now |
Beta Was this translation helpful? Give feedback.
-
warning: going to editorialize a bit here Hot off the presses, we can do these sorts of things out-of-the-box now using PlutoUI.jl and a soon to be released package from the team called MarkdownLiteral.jl. This new package combines the HTML goodness of HypertextLiteral.jl with the sane parsing standards of CommonMark.jl to provide the The example from @dustyirwin might be accomplished with something like this now: # Just until these changes are offish
import Pkg
Pkg.add(url="https://github.com/JuliaPluto/PlutoUI.jl")
Pkg.add(url="https://github.com/JuliaPluto/MarkdownLiteral.jl")
using PlutoUI
using MarkdownLiteral: @mdx
function row_boxes(vec)
PlutoUI.combine() do Child
@mdx("""
$([
Child("var$(v)", CheckBox())
for v ∈ vec
])
""")
end
end
@bind vars row_boxes([1, 2, 3]) For a bunch more customizations you can do/are being experimented with, feel free to follow the discussion here! |
Beta Was this translation helpful? Give feedback.
-
This is great! I can easily see this opening up all kinds of custom UI elements. I tried the example from @icweaver and it works perfectly! To push this a bit further, I tried to label the CheckBox elements, which renders in the cell (albeit a bit awkwardly): This has me thinking... it would be nice to be able pass a UI element label in PlutoUI like we can for widgets in Interact.jl. Has anyone else had success in labeling these input elements? |
Beta Was this translation helpful? Give feedback.
warning: going to editorialize a bit here
Hot off the presses, we can do these sorts of things out-of-the-box now using PlutoUI.jl and a soon to be released package from the team called MarkdownLiteral.jl. This new package combines the HTML goodness of HypertextLiteral.jl with the sane parsing standards of CommonMark.jl to provide the
@markdown
macro (aka@markdownliteral
, aka@mdx
), which will hopefully supplantmd"""
in the future.The example from @dustyirwin might be accomplished with something like this now: