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

Add dynamic select input #524

Closed
josevalim opened this issue Aug 28, 2021 · 8 comments · Fixed by #714
Closed

Add dynamic select input #524

josevalim opened this issue Aug 28, 2021 · 8 comments · Fixed by #714
Labels
discussion Needs to be discussed before moving forward feature New feature or request

Comments

@josevalim
Copy link
Contributor

A dynamic select input is one that gets its possible values from a variable name in the code.

@josevalim josevalim added feature New feature or request discussion Needs to be discussed before moving forward labels Aug 28, 2021
@jeantux
Copy link
Contributor

jeantux commented Oct 11, 2021

This idea is very cool
I will try to work on it, how do you think?

I thought of something like:
In Cell settings, in type select, add an checkbox called "dynamic", that displays an input to type the name of the variable where will get the options or add new option in type called dynamic select.

@josevalim
Copy link
Contributor Author

Another option would be for us to render the select with Kino, but then it may feel a bit "out of place". What are your thoughts here @jonatanklosko?

@jonatanklosko
Copy link
Member

If we render it with Kino, then the select state will be lost whenever we reevaluate the cell, which would be quite annoying.

Regarding implementing it as regular input, a couple things to keep in mind. We need to get the new value whenever someone changes the source variable or when the cell is reevaluted. Also, the evaluator may be busy for a while, so there's also an intermediate loading state. It's definitely doable, but handling all of this seems a bit tricky, while this particular input is more of a convenience. Say we really need to handle dynamic values, then we could do:

values = ["a", "b", "c"]

# --- Answer: [input] ---

value = IO.gets("Answer: ") |> String.strip()

if value not in values do
  raise "expected either of #{inspect(values)}, got: #{inspect(value)}"
end

This also matches what someone would do in a script, which is sort of our point from the beginning. With this in mind, the gain of dynamic select is not clear to me and sounds like an overkill, but feel free to convince me :D

And as a minor detail, it could be a bit confusing that we take the options from a variable, but then still return a newline-terminated string.

@jeantux
Copy link
Contributor

jeantux commented Oct 11, 2021

I understand your point of view, I'm thinking of some solutions to the issues raised in this conversation, for now I'll leave this task on stand by.

@josevalim
Copy link
Contributor Author

The idea of dynamic select came from presentation mode: you may want to parse some data and then generate selects for the user to customize graphs, reports, etc. Here is an example from deepnote: https://deepnote.com/@fs/Programatic-input-values-QAIvOZdTQyiFARcEBxVaEA

I am sure it will be needed at some point but I understand the implementation is likely non-trivial. As you said, in a lot of ways it behaves more like an Elixir cell (e.g. it can go stale too).

@jeantux
Copy link
Contributor

jeantux commented Oct 11, 2021

I imagine that for the user to customize graphics, reports, etc. be really very good. (although there are several details to consider in implementation)
But I'm helping with some more priority activities.

@jeantux
Copy link
Contributor

jeantux commented Oct 11, 2021

Maybe I'll do some sketches 🙂

@josevalim
Copy link
Contributor Author

I have discussed with @jonatanklosko and we are moving all inputs to Kino. This should make this really feasible. So keep posted. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Needs to be discussed before moving forward feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants