Hi everyone,
Here is a small example reproducing my problem :
I would like to show an empty box in the selectizeInput box when nothing is chosen by user in the checkboxgroupinput
I made the connection with observeEvent (objections are welcomed, using loop/"for" probably not the best way), and it works but when 0 group are chosen, it remains on the previous choice. And of course, i would like nothing appears.
library(shiny)
# define dataset
list_group <- c("Group1","Group2","Group3")
liste_ind_group <- list(Group1=c("Monica","Therese"),
Group2=c("Jose"),
Group3=c("Andre","Martina","Pete","Roger"))
liste_id <- sort(c(liste_ind_group[["Group1"]],liste_ind_group[["Group2"]],liste_ind_group[["Group3"]]))
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Test ObserveEvent / UpdateSelectizeInput"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput("type_group", "Groupe Choice", inline=T,
choices = list_group, selected=list_group),
selectizeInput("id_type_group", "Name", choices = liste_id, selected=liste_id, multiple = T),
h6("____________________"),
checkboxInput('selectall_id_type_group', 'Tout / Aucun', T)
),
mainPanel(
)
)
)
# Define server
server <- function(input, output,session) {
observeEvent(input$type_group,{
val <- c()
for(i in 1:length(input$type_group)){
val <- c(val, liste_ind_group[[which(input$type_group[[i]] == list_group)]])
}
# if(!input$type_group) { val <- character(0) } # nothing changes
updateSelectizeInput(
session, 'id_type_group',
choices = val,
selected = val
)
})
observeEvent(input$selectall_id_type_group,{
val <- liste_id
if(!input$selectall_id_type_group)
val <- character(0)
updateSelectizeInput(
session, 'id_type_group',
selected = val
)
})
}
# Run the application
shinyApp(ui = ui, server = server)