Shinytest for a dynamically created UI (with reprex)

Hello,

I am trying to incorporate shinytest into my shinyapp and I am able to run the recording of the test with recordTest() but I end up with the error below . Below I have attached the reprex for you (it is a simple survey where depending on what you answer in the question it will create a certain set of questions on the next screen for you. Just note the package which you need to install for it to work.

#devtools::install_github('mtrybulec/interviewer')
library(interviewer)
#> Loading required package: shiny
#> Loading required package: shinyjs
#> Warning: package 'shinyjs' was built under R version 4.0.3
#> 
#> Attaching package: 'shinyjs'
#> The following object is masked from 'package:shiny':
#> 
#>     runExample
#> The following objects are masked from 'package:methods':
#> 
#>     removeClass, show
#> 
#> Attaching package: 'interviewer'
#> The following object is masked from 'package:shinyjs':
#> 
#>     runExample
#> The following object is masked from 'package:shiny':
#> 
#>     runExample
library(shiny)


ui <- shiny::fluidPage(
  interviewer::useInterviewer(),
  shiny::uiOutput(outputId = "questionnaireOutput")
)


server <- 
function(input, output, session) {
  
  responses <- interviewer::buildResponses(
    id = c("a", "b", "c"),
    label = c("response A", "response B", "response C")
  )
  
  output$questionnaireOutput <-
    interviewer::questionnaire(
      label = "Loop DEMO",
      welcome = list(
        shiny::p("Welcome!"),
        shiny::HTML("<p>This demo shows how <strong>loops</strong> can be defined in <strong>interviewer</strong>.</p>")
      ),
      
      interviewer::question.multiple(
        id = "LoopSource",
        label = "Loop source (two questions will be asked for each response mentioned here, in random order)",
        responses = responses
      ),
      
      interviewer::pageBreak(),
      
      function() {
        result <- list()
        responseIds <- getResponseIds("LoopSource")
        responseIds <- responseIds[sample(length(responseIds))] # randomize subsequent blocks
        
        for (responseId in responseIds) {
          responseLabel <- responses[which(responses$id == responseId), "label"]
          
          result <- append(
            result,
            list(
              interviewer::question.single(
                id = paste0("LoopQuestion1", responseId),
                label = sprintf("Loop question 1 for '%s'", responseLabel),
                responses = responses
              ),
              
              interviewer::question.single(
                id = paste0("LoopQuestion2", responseId),
                label = sprintf("Loop question 2 for '%s'", responseLabel),
                responses = responses
              ),
              
              interviewer::pageBreak()
            )
          )
        }
        
        result
      },
      
      interviewer::question.single(
        id = "Final",
        label = "Final",
        responses = responses
      ),
      
      goodbye = "Done!",
      exit = function(data) {
        cat("Done:\n")
        print(data)
      }
    )
  
}




shinyApp(ui, server)
#> 
#> Listening on http://127.0.0.1:5136

Created on 2021-04-07 by the reprex package (v0.3.0)

After you have the shiny app working you can just run recordTest in the right folder with the app.R file from above and you should see the error after you made your full selection of actions that need to be captured. I can share my exact test scenario but other instances trigger it too.

library(shinytest)

shinytest::recordTest("loop_simple_test")

Running mytest.R Error in session_makeRequest(self, private, endpoint, data, params, headers) : 
  Can't find variable: $escape

@nirgrahamuk - I created a new topic with the reprex now :slight_smile: Any thoughts?

my thought is that its something screwy with javascript input bindings that rely on Shiny.$escape()
I recommend you raise an issue with the shinytest developers.
Issues · rstudio/shinytest (github.com)

1 Like

Anyone? I have posted on the package's github as well but no luck.

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.