title: R Shiny : 2 checkboxGroupInput names or values in an object
body: <p>*
  *
  Hello, I'm new to R and I don't understand why my code does not work as expected. If you see where I'm wrong, please tell me.</p>
  
  <p>I have an object named VAR which must take values of the checked boxes of a checkboxGroupInput named input$dynamic_provinces OR it must take values of another checkboxGroupInput named input$dynamic depending on the choices we make in the "Provinces" tab.</p>
  
  <p>And I have another object named CHAMP which value is "PC" or "PROVINCE".
  If we select 1 or 2 Provinces, selectionBI is created searching in "PROVINCE" variable, but if we select the 3 Provinces, selectionBI is created on the "PC" variable.</p>
  
  <p>And I don't manage to give the checkboxGroupInput values to VAR, so my code returns 0. Please, try this reproducible example.</p>
  
  <p>This is my Ui.R :</p>
  
  <pre><code>library(shiny)
  library(plyr)
  library(DT)
  library(shinydashboard)
  library(rgdal)
  library(stringr)
  library(XML)
  library(reshape2)
  library(plotrix)
  
  dynamic_choices = c("Town 1"="01", "Town 2"="02", "Town 3"="03", "Town
                      4"="04", "Town 5"="05", "Town 6"="06",
                  "Town 7"="07", "Town 8"="08", "Town 9"="09", "Town 
                      10"="10", "Town 11"="11", "Town 12"="12",
                  "Town 13"="13", "Town 14"="14", "Town 15"="15", "Town 
                      16"="16", "Town 17"="17", "Town 18"="18",
                  "Town 19"="19", "Town 20"="20")
  
  
  
  ui &lt;- dashboardPage(
    dashboardHeader(
      title = "Test"),
  
     dashboardSidebar(
      sidebarMenu(
        id = "Menu1",
    menuSubItem("Provinces",icon = icon("circle-o"), tabName = 
                    "provinces"),
    menuSubItem("Cities",icon = icon("spinner"), tabName = "cities"),
    menuItem(strong("Population datas"), tabName = "data_pop", icon = 
          icon("user")),
    menuSubItem("Population 1",icon = icon("users"), tabName = 
          "Population_1"))),
  
   dashboardBody(
     tabItems( 
       tabItem(tabName = "provinces",
            fluidRow(
              box(title = "Provinces level", width = 3, solidHeader = 
                  TRUE, status = "primary",
                  checkboxGroupInput("dynamic_provinces", label = "", 
                  c("North","South","East")))
            )
    ),
    tabItem(tabName = "cities",
            box(title = "Cities level", width = 9, solidHeader = TRUE, 
                 status = "primary",
                checkboxGroupInput("dynamic", label = "", 
                 c(dynamic_choices))) # f. de box
  
    ),
    tabItem(tabName = "Population_1",
            fluidRow(
              column(width = 4,
                     box(title = "Features", width = NULL, solidHeader = 
                          TRUE, status = "primary",
                         DT::dataTableOutput("dfBI"))
              )
            )
    )
  )
  )
  )
  </code></pre>
  
  <p>And this my Server.R :</p>
  
  <pre><code>########################## Init answers provinces 
  
  selection = list("North"=c("Town 1"="01","Town 2"="02","Town 
                              3"="03","Town 4"="04",
                        "Town 5"="05","Town 6"="06","Town 7"="07","Town 
                               8"="08",
                        "Town 9"="09"),
               "South"=c("Town 10"="10","Town 11"="11","Town 
                          12"="12","Town 13"="13",
                       "Town 14"="14","Town 15"="15","Town 16"="16","Town 
                           17"="17"),
               "East"=c("Town 18"="18","Town 19"="19","Town 20"="20"))
  
  
  shinyServer(function(input, output, session) {
  
    ########################### MATCHES CHECKBOXES PROVINCES/CITIES 
  
   observeEvent(input$dynamic_provinces, {
      selected = c()
  
   for (s in input$dynamic_provinces) {
    selected = c(selected, selection[[s]])
   }
  
   if (is.null(selected)) {
    selected = character(0)
    VAR &lt;- 0
   }
   updateCheckboxGroupInput(session, "dynamic", selected = selected)
  
   if (length(input$dynamic_provinces) == 1){(CHAMP &lt;- "PROVINCE")
    VAR &lt;- "input$dynamic_provinces"}
  
   if (length(input$dynamic_provinces) == 2){(CHAMP &lt;- "PROVINCE")
    VAR &lt;- "input$dynamic_provinces"}
  
   if (length(input$dynamic_provinces) == 3){(CHAMP &lt;- "PC")
    VAR &lt;- c("01","02","03","04","05","06","07","08","09","10","11",
             "12","13","14","15","16","17","18","19","20")}
  
   }, ignoreNULL = FALSE)
  
   ###################### POPULATION 1 TAB
  
   selectionBI &lt;- reactive({filter(DTtest, CHAMP %in% 
                            VAR)})
  
   ######################## TABLE dfBI : FEATURES POPULATION 
  
  selectionBITable &lt;- reactive({
  tmp &lt;- selectionBI()
  dfBI &lt;- data.frame(
    Rubriques = c("Number of residents", 
                  "Men", 
                  "Women", 
                  "Minors", 
                  "Boys",
                  "Girls",
                  "Adults",
                  "Men",
                  "Women"),
    Nombre = c(
      NROW(selectionBI()),
      NROW(filter(tmp, S == "1")),
      NROW(filter(tmp, S == "2")),
      NROW(filter(tmp, AGER &lt; 18)),
      NROW(filter(tmp, AGER &lt; 18 &amp; S == "1")),
      NROW(filter(tmp, AGER &lt; 18 &amp; S == "2")),
      NROW(filter(tmp, AGER &gt; 17)),
      NROW(filter(tmp, AGER &gt; 17 &amp; S == "1")),
      NROW(filter(tmp, AGER &gt; 17 &amp; S == "2")))
  )
  dfBI
  })
  
   output$dfBI &lt;- renderDataTable(selectionBITable(),options = 
   list(paging = FALSE,ordering = FALSE,searching = FALSE,info = FALSE))
  })
  </code></pre>
  
  <p>And an example of the DTtest data frame :</p>
  
  <pre><code>PC;S;AGER;PROVINCE;KAR
  01;1;34;North;
  01;2;32;North;
  01;1;7;North;
  02;1;22;North;
  02;2;20;North;
  03;2;75;North;
  04;1;45;North;
  04;2;42;North;
  04;2;15;North;
  05;1;67;North;
  05;1;60;North;
  05;1;56;North;
  05;2;48;North;
  06;1;25;North;01
  06;2;27;North;01
  06;2;35;North;01
  06;1;11;North;01
  06;1;42;North;02
  06;2;37;North;02
  06;2;13;North;02
  06;1;48;North;03
  06;2;43;North;03
  06;1;17;North;03
  06;1;15;North;03
  06;2;26;North;03
  07;1;36;North;04
  07;2;35;North;04
  07;1;10;North;04
  07;1;38;North;04
  07;2;35;North;04
  07;2;10;North;04
  07;2;27;North;05
  07;2;8;North;05
  07;1;25;North;05
  07;2;22;North;05
  07;1;31;North;06
  07;2;32;North;06
  07;1;7;North;06
  07;1;5;North;06
  07;1;68;North;06
  07;2;65;North;06
  08;1;72;North;
  09;1;27;North;
  09;2;25;North;
  09;2;1;North;
  10;1;43;South;
  10;2;40;South;
  10;1;20;South;
  10;1;12;South;
  11;2;86;South;
  12;1;23;South;
  12;2;21;South;
  12;1;33;South;
  12;2;32;South;
  12;2;8;South;
  13;1;42;South;
  13;2;41;South;
  13;2;17;South;
  18;1;35;East
  18;2;34;East
  18;2;13;East
  19;1;21;East
  19;2;23;East
  19;1;35;East
  19;2;32;East
  19;1;5;East
  20;1;53;East
  20;2;51;East
  20;2;21;East
  20;2;17;East
  20;1;13;East
  </code></pre>
  
  <p>Please, if you see where is the problem, tell me.</p>
  
  <p>Thanks a lot.</p>