shinysurveys icon indicating copy to clipboard operation
shinysurveys copied to clipboard

Bug: Requiring an answer on "Matrix Input" breaks the app

Open aalexee opened this issue 1 year ago • 0 comments

First of all, thanks a lot for putting together this package. I am super excited to see Shiny developing in this direction and I greatly appreciate your contribution. I used Qualtrics a lot, but I really hate it for being slow and not being able to do things programmatically.

I am not sure if the package is maintained anymore, but I encountered a breaking change. It happens when you require a matrix input. Here is the minimal working example, just a slight modification of the code on the package website.

library(shiny)
library(shinysurveys)

df <- data.frame(
  question = c("What is your favorite food?", "What is your favorite food?"),
  option = c("Sushi", "Pizza"),
  input_type = c("matrix", "matrix"),
  input_id = c("favorite_food", "favorite_food"),
  dependence = c(NA, NA),
  dependence_value = c(NA, NA),
  required = c(T, T)
)

ui <- fluidPage(
  surveyOutput(df = df,
               survey_title = "Hello, World!",
               survey_description = "Welcome! This is a demo survey showing off the {shinysurveys} package.")
)

server <- function(input, output, session) {
  renderSurvey()

  observeEvent(input$submit, {
    showModal(modalDialog(
      title = "Congrats, you completed your first shinysurvey!",
      "You can customize what actions happen when a user finishes a survey using input$submit."
    ))
  })
}

shinyApp(ui, server)

When you run the app and select any option, you get the following error message

Warning: Error in &&: 'length = 3' in coercion to 'logical(1)'
  49: FUN
  48: vapply
  47: checkRequired_internal
  45: ::
shiny
observe
  44: <observer>
   1: runApp

I tried to figure out what is going on. Apparently something is wrong with the function checkRequired_internal, but I am not that good at coding to fix this myself. I am assuming that the issue is in the file utils_render-survey.R where all(vapply(required_inputs_vector, checkIndividual, input = input, FUN.VALUE = logical(1), USE.NAMES = FALSE)) is called.

If anyone has an idea of how to fix this, it would be great.

aalexee avatar Oct 20 '23 13:10 aalexee