Not disable check boxes (At least 1 should be activated)

Hi all,

Is there away so that at least 1 check box is clicked always. If the user is going to unselect all boxes, that should not be possible. So basically at least 1 box should be selected

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(DT)
library(tidyverse)
```

Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
checkboxGroupInput(inputId = "ID", "Species", choices = unique(iris$Species), selected = as.character(unique(iris$Species)),inline = TRUE)
DT::DTOutput("iris_table")

table_iris <- reactive({
  print(input$ID)
  if(!is.null(input$ID))
  {
    iris <- iris %>% filter(Species %in% input$ID)
  }
  else
  {
    iris
  }
})

output$iris_table <-
        DT::renderDT({
            datatable(table_iris(),
                      rownames = F,
                      escape = FALSE) 
        })
```

To me that sounds confusing for the user , personally I think I'd get frustrated if I want to deselect something and can't.
Would an error message do?

 table_iris <- reactive({
    print(input$ID)
    validate(need ( !(is.null(input$ID)),
             "Please select at least one species")
    )
      iris <- iris %>% filter(Species %in% input$ID)
      return(iris)
  })
  

If not maybe you can use the updateCheckboxGroupInput() function and check a specific box automatically?

something like

  observe({
    if( is.null(input$ID) ){
      updateCheckboxGroupInput(session, "ID", selected =as.character(unique(iris$Species)))
    }
  })

Thanks..............

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.