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

FR: let selectizeInput choose same choice repeatedly. #2939

Open
SarenT opened this issue Jun 25, 2020 · 5 comments
Open

FR: let selectizeInput choose same choice repeatedly. #2939

SarenT opened this issue Jun 25, 2020 · 5 comments
Labels
UI toolkit: selectInput Issues related to selectInput()

Comments

@SarenT
Copy link

SarenT commented Jun 25, 2020

I wanted to make a formula editor to assist users while writing formulas with variable names. The aim is to let users calculate new variables for a data frame based on existing variables. If there are many variable names, users won't be able to keep those in mind, hence the assist. selectizeInput is almost perfect for this case. It allows predefined items (e.g. VAR1, VAR2, ...., +, /, -, *, sqrt(, log(, lag(, first(, ),....) but it also allows users to add new items, on the go. e.g. user may want to mutliply a variable with an arbitrary number e.g. 12231232.3. This formula can be converted into a string, parsed and evaluated. Only problem is that users can't add same item twice. sqrt(x^2 + y^2) doesn't work since, ^ and 2 appear twice.

I wonder if this makes sense for other users? There maybe other scenarios, where this can be useful (some ordered selection of items for probabilities? e.g. picking multiple identical items from a collection)

@cpsievert
Copy link
Collaborator

Only problem is that users can't add same item twice.

It's possible to implement this capability with shiny's reactive programming tools. Sounds like a situation where you want to combine something like submitButton() with reactiveVal() (to keep track of what the user has submitted). Anyway, this is more of a question than a feature request at the moment, so I'm closing, but feel free to cross-post on https://community.rstudio.com, which is a better venue for getting help with questions of this sort.

@SarenT
Copy link
Author

SarenT commented Jun 25, 2020

I don't think this was a question because I can implement this with the programming tools. However, selectizeInput can have a parameter (allowRepeat = FALSE) to let repeated values to be added. That would be a feature improvement and it would allow such input:
blue blue red red red blue red
or in my case I would let my users type in formulas with auto-complete assist (item 2 appears twice):
2 * length / (time ^ 2)

Currently, I have an observeEvent on a selectInput. Upon selection, the variable name is concatenated to the textInput.
e.g.
user types into textInput: 2 *
user selects: "Length"
shiny updates textInput: 2 * length
and so on.
This takes up more space (an extra select input), which could be achieved with a single selectizeInput OR actually textInput with word auto-completion.

@cpsievert
Copy link
Collaborator

Oh ok, sorry for misunderstanding the issue! By any chance, does the ability to have repeated labels help you workaround the issue (e.g., selectInput("x", "choose", c("^" = 1, "^" = 2)))?

@cpsievert cpsievert reopened this Jun 25, 2020
@SarenT
Copy link
Author

SarenT commented Jun 25, 2020

Question is how many times user will need it? What if it is needed 3 or 5 times? Also it will be ugly to see same item repeated mutliple times in the pop-up list.

@cpsievert cpsievert added the UI toolkit: selectInput Issues related to selectInput() label Aug 18, 2020
@ismirsehregal
Copy link
Contributor

Just as a workaround: You could update the choices after each selection, to always have "one more" available:

library(shiny)

ui <- fluidPage(
  selectInput("x", "choose", c("^" = 1), multiple = TRUE)
)

server <- function(input, output, session) {
  observeEvent(input$x, {
    choices <- seq_len(length(input$x)+1)
    names(choices) <- rep("^", length(choices))
    updateSelectInput(session, "x", choices = choices, selected = isolate(input$x))
  })
}

shinyApp(ui, server)

screen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI toolkit: selectInput Issues related to selectInput()
Projects
None yet
Development

No branches or pull requests

3 participants