How do I populate select dropdown from an array of strings?

I have an array of strings that I want to use to populate an input select dropdown element in Pluto.

Without any detailed documentation I’ve been really struggling. So far, I have found only one way to create the dropdown:

md"""
$(@bind sites html"<select>
<option value='None'>Select a Site</option>
<option value='S1'>Site 1</option>
<option value='S2'>Site 2</option>
</select>")
"""

However, I don’t want to populate it manually like this. I want to use a preexisting array to fill the option values and the text in the dropdown. How can I do this?

Use Select from GitHub - JuliaPluto/PlutoUI.jl

Edit:
if you want to programmatically construct the HTML instead of using PlutoUI, this package is very helpful: GitHub - JuliaPluto/HypertextLiteral.jl: Julia library for the string interpolation of HTML and SVG

1 Like

I had not imported Select, so this works, thank you!

begin
	import Pkg
	Pkg.activate(mktempdir())
	Pkg.add([
			Pkg.PackageSpec(name="PlutoUI", version="0.7")])
	using PlutoUI
end			

site1 = @bind Site1 Select(sites)

That’s nice!

1 Like