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

Empty list of choices checkboxGroupInput #1649

Closed
nomtrosk opened this issue Apr 4, 2017 · 6 comments
Closed

Empty list of choices checkboxGroupInput #1649

nomtrosk opened this issue Apr 4, 2017 · 6 comments
Assignees

Comments

@nomtrosk
Copy link

nomtrosk commented Apr 4, 2017

I see that the latest release of shiny (V 1.0.1) change the way you are allowed to define a group of checkboxes. This change clashes with my use case of checkboxes and I just wanna check that my case has been considered at design.

I use checkboxes as a user controlled list where the user can add items (done with updateCheckboxGroupInput) and remove them again by checking and push a remove button. Think of the way you delete files in rstudio. This use case require me to initialize an empty checklist but the new release prevent me from doing that by throwing an error: "Please specify a non-empty vector for choices"

I find my example a valid case where you have to be able to initialize a checkbox group with choice = c(). What do you think? Has this use case been considered?

Henrik

@bborgesr
Copy link
Contributor

bborgesr commented Apr 4, 2017

Do you have a minimal repro? Does this not work for you?

library(shiny)
ui <- fluidPage(checkboxGroupInput("check", "checkboxes", character(0)))
server <- function(input, output, session) {}
shinyApp(ui, server)

@wch
Copy link
Collaborator

wch commented Apr 4, 2017

It was an unintentional change in 1.0.1 that choices=NULL no longer works. (c() evaluates to NULL.) As @bborgesr mentioned, for now you can use character(0).

bborgesr added a commit that referenced this issue Apr 4, 2017
…r `c()` to keep backward compatibility with Shiny < 1.0.1 (fixes #1649)
@bborgesr bborgesr self-assigned this Apr 4, 2017
@bborgesr bborgesr added the review label Apr 4, 2017
@nomtrosk
Copy link
Author

nomtrosk commented Apr 5, 2017

@bborgesr Thanks for the workaround with character(0). It solved my immediate problem.
@wch At least it seems inconsistent that the default argument produce an error :)

Thank you for your help. I appreciate it!

@wch wch closed this as completed in #1652 Apr 5, 2017
wch pushed a commit that referenced this issue Apr 5, 2017
…1652)

* allow the `choices` argument in `checkboxGroupInput()` to be `NULL` or `c()` to keep backward compatibility with Shiny < 1.0.1 (fixes #1649)

* use vapply

* added one more test; reimplemented logic for checking if choice args are null
@wch wch removed the review label Apr 5, 2017
@bborgesr
Copy link
Contributor

bborgesr commented Apr 5, 2017

@harasmussen: given that this broke backward compatibility, we also fixed this problem in the development version of Shiny just now. So if you don't want to change your code, just install Shiny from github:

devtools::install_github("rstudio/shiny")

As for the fact that it seems inconsistent that the default argument produces an error, I agree with you that that was less than ideal. It used to be that choices didn't have a default value - it used to be a required argument. In order to allow HTML for the labels of checkboxes though, it can no longer be required. Ideally, we would just get rid of choices and require choiceNames and choiceValues. But that of course, would break ALL apps that use checkboxGroupInput! So we need to give default values to all three of those arguments... As this whole issue pointed out, it's hard to build new features of top of software that wasn't designed with these in mind. Hopefully, we now achieved that for this one case, at least.

Thanks for the report!

dmpe pushed a commit to dmpe/shiny that referenced this issue Apr 5, 2017
…studio#1652)

* allow the `choices` argument in `checkboxGroupInput()` to be `NULL` or `c()` to keep backward compatibility with Shiny < 1.0.1 (fixes rstudio#1649)

* use vapply

* added one more test; reimplemented logic for checking if choice args are null

# Conflicts:
#	NEWS.md
@nomtrosk
Copy link
Author

nomtrosk commented Apr 6, 2017

@bborgesr Nice! I was looking for the name/value separation :).

@worker-wang2019
Copy link

Sorry to bring this back up again . I am still getting this error in year of 2019

Loading required package: shiny
Error in normalizeChoicesArgs(choices, choiceNames, choiceValues) :
Please specify a non-empty vector for choices (or, alternatively, for both choiceNames AND choiceValues).

and it all begins with running the sample app from Rstudio .
IT says it need update version of shiny , but when I tried to instll from github , it says

package ‘fastmap’ is not available (for R version 3.5.1)
any one can help ?

library(shiny)

ui <- fluidPage(

titlePanel("Old Faithful Geyser Data"),

sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),

  mainPanel(
     plotOutput("distPlot")
  )

)
)

server <- function(input, output) {

output$distPlot <- renderPlot({

  x    <- faithful[, 2] 
  bins <- seq(min(x), max(x), length.out = input$bins + 1)
  

  hist(x, breaks = bins, col = 'darkgray', border = 'white')

})
}

shinyApp(ui = ui, server = server)

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

4 participants