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

Clearing all checkboxes in checkboxGroupInput doesn't qualify as an event for observeEvent #1902

Closed
EmileArseneault opened this issue Dec 8, 2017 · 5 comments

Comments

@EmileArseneault
Copy link

When unselecting all checkboxes of a checkboxGroupInput, observeEvent does not respond to the input change but observe does. I think it would be logical that observeEvent react to the fact that the input was cleared and for consistency with observe as well.

Here is a minimal working example of what I found.

library(shiny)

ui <- fluidPage(
  fluidRow(
    checkboxGroupInput('shinyCheckBox',
                       label = NULL,
                       c('One',
                         'Two',
                         'Three'))
  )
)

server <- function(input, output, session){
  
  observeEvent(input$shinyCheckBox, {
      print('Shiny Checkbox observeEvent changed')
  })
  
  observe({
    a <- input$shinyCheckBox
    print('Shiny Checkbox observe changed')
  })
  
}

shinyApp(ui = ui, server = server)

Hope it helps !

@bklingen
Copy link

bklingen commented Dec 8, 2017

You need to include ignoreNULL=FALSE in the observeEvent statement because checkboxGroupInput is NULL when no choices are selected.

library(shiny)

ui <- fluidPage(
  fluidRow(
    checkboxGroupInput('shinyCheckBox',
                       label = NULL,
                       c('One',
                         'Two',
                         'Three'))
  )
)

server <- function(input, output, session){
  
  observeEvent(input$shinyCheckBox, {
      print('Shiny Checkbox observeEvent changed')
  }, ignoreNULL=FALSE)
  
  observe({
    a <- input$shinyCheckBox
    print('Shiny Checkbox observe changed')
  })
  
}

shinyApp(ui = ui, server = server)

@EmileArseneault
Copy link
Author

Thanks for the precision !

I didn't know observeEvent had options like this.
But shouldn't checkboxGroupInput be an empty list instead of NULL then ?
To me it makes no sense that observeEvent and observe behave differently in this situation.

@daattali
Copy link
Contributor

@EmileArseneault an empty vector IS the same as NULL. Try this: identical(c(), NULL)

You're noticing a little-known feature of observeEvent. It may be weird, but it's actually useful that they chose this as the default behaviour. Before observeEvent came into existence, a lot of my observers had if(is.null(input$x)) return() because I had to manually check if the value is null. Thanks for observeEvent and its default value of ignoreNULL, that's not required anymore.

@bborgesr bborgesr added this to the 1.2 milestone Apr 11, 2018
@wch
Copy link
Collaborator

wch commented Apr 11, 2018

For future reference: it should probably give character(0) instead of NULL.

@jcheng5 jcheng5 modified the milestones: 1.2, 1.3 Sep 14, 2018
@jcheng5
Copy link
Member

jcheng5 commented Sep 14, 2018

observeEvent actually uses req and req(input$checkboxes) should probably mean "one of these checkboxes should be checked"? I can see how it feels like a slight misfit for observeEvent though.

@jcheng5 jcheng5 closed this as completed Sep 14, 2018
j-harbin added a commit to ArgoCanada/argoFloats that referenced this issue Jul 8, 2021
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

6 participants