Reputation: 2031
I would like for an observeEvent
to trigger when the list of inputs is cleared.
Here is a little example app:
library(shiny)
ui <- fluidPage(
selectizeInput(inputId='select',
label='Select something',
multiple=TRUE,
choices=letters[1:3])
)
server <- function(input, output){
observeEvent(input$select, {
print(input$select)
})
}
shinyApp(ui=ui, server=server)
Now each time I select another letter the observeEvent
is triggered. Also removing a letter triggers the event. However, removing the final letter does not seem to trigger anything.
I tried the solution here but it does not seem to apply to my case (or I do not manage to get it to work).
So my expected output would be that after selecting a
it prints "a"
, but then after deleting a
, that it prints something as well (be it NULL
or ""
).
Upvotes: 5
Views: 2362
Reputation: 29407
observeEvent
has a number of arguments
observeEvent(eventExpr, handlerExpr, event.env = parent.frame(), event.quoted = FALSE, handler.env = parent.frame(), handler.quoted = FALSE, label = NULL, suspended = FALSE, priority = 0, domain = getDefaultReactiveDomain(), autoDestroy = TRUE, ignoreNULL = TRUE, ignoreInit = FALSE, once = FALSE)
including ignoreNULL
, which is set to TRUE
by default, simply change that to FALSE
observeEvent(input$select, {
print(input$select)
},ignoreNULL = FALSE)
Upvotes: 6
Reputation: 86
You can use observe instead of observeEvent.
library(shiny)
ui <- fluidPage(
selectizeInput(inputId='select',
label='Select something',
multiple=TRUE,
choices=letters[1:3])
)
server <- function(input, output){
observe({
print(input$select)
})
}
shinyApp(ui=ui, server=server)
Upvotes: 4