Reactive widgets and datasets

Hi,
I am working on a Shiny app.
My ui.R

fluidPage(
                                     
                                     titlePanel("Downloading Data"),
                                     
                                     fluidRow(
                                        
                                        column(3, wellPanel(
                                           selectInput("input_type", "Choose chapter",
                                                       c( "Chapter 1" = "ch1",
                                                         "Chapter 2" = "ch2"
                                                       )
                                           ),
                                        br(),
                                        br(),
                                           # This outputs the dynamic UI component
                                           uiOutput("ui"),
                                        # Button
                                        downloadButton("downloadData", "Download")
                                        )),
                                        
                                        column(8,
                                               DT::dataTableOutput("table")
                                        )
                                     )
                                        
                                     )

When selecting input_type depending on item selected a radiobutton is shown. My server.ui:

## Data tab
  
  output$ui <- renderUI({
    if (is.null(input$input_type))
      return()
    
    # Depending on input$input_type, we'll generate a different
    # UI component and send it to the client.
    switch(input$input_type,
           "ch1" = radioButtons("rb1", "Selection 1",
                                choices = c("Reason 1" = "db1",
                                            "Reason 2" = "db2"),
                                selected = "db1"
           ),
           "ch2" = radioButtons("rb2", "Selection 2",
                                choices = c("Answer 1" = "db3",
                                            "Answer 2" = "db4"
           )
  })
  
  # Reactive value for selected dataset ----
  datasetInput <- reactive({
    if (input$input_type == "ch1" & input$rb1 == "db1") {data <- db1}
    else if (input$input_type == "ch1" & input$rb1 == "db2") {data <-db2} 
     else if (input$input_type == "ch2" & input$rb2 == "db3") {data <-db3} 
    else if (input$input_type == "ch2" & input$rb2== "db4") {data <-db4} 
    return(data)      
    })
  
  # Table of selected dataset ----

  output$table <- DT::renderDataTable(
    datasetInput(), options = list(
      lengthChange = FALSE,
      initComplete = JS(
        "function(settings, json) {",
        "$(this.api().table().header()).css({'background-color': '#42f', 'color': '#fff'});",
        "}"))
  )

So selectInput activates different radiobuttons rb1 and rb2. Based on selection on this radiobuttons different dbs are shown.
App works but some error is thrown:

Warning: Error in if: argument is of length zero
119: reactive:datasetInput

What is going wrong?
Thx

You haven't accounted for what should happen if input$rb1 or input$rb2 have no content.
As a programmer we might assume that if theres not even a value to test, then R should should fail the evaluation as FALSE, but in R we need to be a little more explicit than other language perhaps.
anyway, here is one possible solution

 datasetInput <- reactive({
    req(input$input_type)
    if(length(input$rb1)==0) rb1<-"" else   rb1<- input$rb1
    if(length(input$rb2)==0) rb2<-"" else   rb2<- input$rb2
    
    data <- NULL
    
    if (input$input_type == "ch1" & rb1 == "db1") {data <- mtcars}
    else if (input$input_type == "ch1" & rb1 == "db2") {data <-iris} 
    else if (input$input_type == "ch2" & rb2 == "db3") {data <-mpg} 
    else if (input$input_type == "ch2" & rb2== "db4") {data <-iris} 
    return(data)      
  })

note: I used datasets I had access to in order to demo your app to myself. (mtcars, iris,mpg )