Argument is of length zero error

I tried to write an app plot output with an interactive element for selecting the fill variable using selectInput, however, it seems to work with 2 (ASA, Frailty, in the sample below) of the 5 selections, but with the other 3, I am getting the argument is of length zero error. I am not sure why that is happening?

selectInput(NS(id, "secondary"),
                  label = "Choose Secondary Factors",
                  c("ASA" = "ASA",
                    "Frailty" = "frailty",
                    "Obesity" = "Obesity",
                    "Gender" = "GENDER",
                    "SIMD" = "SIMD_Quintile"))
plot <- dataset() %>% 
          ggplot(aes(x = age_grouped)) +
          geom_bar(aes_string(fill = input$secondary)) +
          scale_fill_brewer(type = "qual", palette = "RdYlBu", direction = -1, na.value = "grey", name = varName()) +
          labs(x = "Age Group",
               y = "Number of Patients",
               title = "Patient Age") +
          theme_minimal()
structure(list(ASA = structure(c(2L, 2L, 2L, 2L, 2L, 3L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L), .Label = c("1", "2", "3", "4"
), class = "factor"), Obesity = structure(c(3L, 3L, 4L, 4L, 3L, 
4L, 3L, 4L, 5L, 3L, 4L, 4L, 5L, 5L, 4L), .Label = c("Underweight", 
"Normal", "Overweight", "Class I", "Class II", "Class III", "Super"
), class = "factor"), frailty = structure(c(NA, NA, 3L, NA, 4L, 
5L, NA, 4L, 4L, 3L, 4L, NA, 5L, NA, NA), .Label = c("0", "1", 
"2", "3", "4", "5", "6"), class = "factor"), SIMD_Quintile = structure(c(3L, 
2L, 4L, 1L, 5L, 5L, NA, 1L, 4L, 3L, NA, 1L, 2L, NA, 4L), .Label = c("1", 
"2", "3", "4", "5"), class = "factor"), GENDER = c("MALE", "FEMALE", 
"MALE", "MALE", "MALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", 
"MALE", "FEMALE", "FEMALE", "FEMALE", "MALE")), row.names = c(NA, 
-15L), class = c("tbl_df", "tbl", "data.frame"))

I am trying to do this within modules. Any explanation as to why this might happen would be appreciated

Tried to reproduce but received several errors including no function varName, no age_grouped object, etc.

If you ignore the R Shiny component entirely and just try to plot the dataset using the 3 selections that don't work, do you get the expected plot?

I apologies, it turns out to be a stupid spelling mistake within varName(). I didn't spot it because I didn't think it would affect subsequent lines in the code. I should probably delete the topic.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.