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

@map Syntax to twice dereference observable? #379

Open
jacobadenbaum opened this issue Dec 14, 2020 · 0 comments
Open

@map Syntax to twice dereference observable? #379

jacobadenbaum opened this issue Dec 14, 2020 · 0 comments

Comments

@jacobadenbaum
Copy link

jacobadenbaum commented Dec 14, 2020

Suppose I have the following example.

opt1 = widget(("Option 1", "Option 2"), label = "First Layer")
opt2 = Interact.@map begin
    if &opt1 == "Option 1"
        return dropdown(["A", "B", "C"], label = "Second Layer")
    else
        return dropdown(["A", "C"], label = "Second Layer")
    end
end

Now, I want to use the value of the dropdown menu in opt2 to do something (like, generate a plot). But when I run

val = Interact.@map do_work(&opt2)

I get the ui element that correspond to the dropdown menu, instead of it's value. I would have thought that the natural way to do this would be:

val = Interact.@map do_work(&&opt2)

but this syntax is not supported and returns an error. Is it possible to support something like this? I came upon this when I was trying to dynamically generate a UI for several different types of plots, where there are specific options that are only available for certain types of plots.

For what it's worth, I'm currently, I'm getting around this by doing something like the following:

opt2_val = Observable{Any}()
opt2 = Interact.@map begin
    if &opt1 == "Option 1"
        s =  dropdown(["A", "B", "C"], label = "Second Layer")
    else
        s = dropdown(["A", "C"], label = "Second Layer")
    end
    opt2_val[] = s[]
    map!(identity, opt2_val, s)
end
val = Interact.@map do_work(&opt2_val)

This seems to work, but it's awkward to do and I'm worried that it's not best practices.

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

1 participant