ExpectUpdate for a submit button

Hi all,

I came across the below function to test the shiny app.This is really nice. But I have a concern here what if there are 3 inputs together and then a output. Refer Example section

app <- ShinyDriver$new(getwd()
expectUpdate(app, xcol = "Sepal.Width", output = "plot1")
expectUpdate(app, ycol = "Petal.Width", output = "plot1")
expectUpdate(app, clusters = 4, output = "plot1")

I have to select xcol, ycol and click on submit button to see the plot. Will the below code work?

expectUpdate(app, xcol = "Sepal.Width", ycol = "Petal.Width", Submit = 1, output = "plot1")

I don't see why not, according to the documentation multiple inputs can be passed.

Just be careful as in a traditional app a button press will only have the value 1 after the first time it's pressed before it's pressed for the second time

I just tried with this code. But getting error. not sure why? Can you please help me

expectUpdate(app, xcol = "Sepal.Width", ycol = "Petal.Width", Submit = 1, output = "plot1")
Error: Updating ‘xcol’, ‘ycol’, ‘Submit’ did not update ‘plot1’, or it is taking longer than 3000 ms.

Is everything hooked up so that the 3 inputs do influence plot1? Does plot1 render fast or after longer than 3 seconds?
These are the first two questions to consider.

Yes everything is fine. And plot is coming within 3s as wel

Can you provide a reprex so I can play with it?

Hi Nir,

That was just a sample. below is the actual code for that but this is in markdown. I tried with below

expectUpdate(app, Tic = 'setosa', Date = as.Date('2019-12-27'), Submit = 1, output = 'table', timeout = 3000)
title: "Untitled"
runtime: shiny
    orientation: columns
    vertical_layout: fill

```{r setup, include=FALSE}


Column {data-width=650}

### Chart A

df <- structure(list(Date = structure(c(1541662915.921, 1541662949.842, 
1541662949.845, 1541662949.845, 1541662993.957, 1541662915.921, 
1541662949.842, 1541662949.845, 1541662949.845, 1541662993.957
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), Date1 = structure(c(17843, 
17843, 17843, 17843, 17843, 17843, 17843, 17843, 17843, 17843
), class = "Date"), ID = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L), .Label = c("AAA", "BBB"), class = "factor"), 
    Value = c(68, 70175, 71107, 702175, 72638, 7238, 739, 738469, 
    75901, 7106), Status = structure(c(1L, 1L, 2L, 2L, 1L, 2L, 
    1L, 1L, 2L, 1L), .Label = c("Approved", "Pending"), class = "factor")), row.names = c(NA, 
-10L), class = "data.frame")

dateRangeInput("Date","",start = '', end = '',format = "yyyy-mm-dd",separator = "-")
selectInput("Tic","",choices = c("ALL",as.character(df$ID)),selected = "ALL")

data2 <- reactiveVal(df[1:2, ])

      if(input$Date == ""){
      df1 <- df[1:2, ]
      else if (input$Date != ""){
      df1 <- df
    } else {
      df1 <- df %>% filter(Date %in% input$Date && ID %in% input$Tic)

output$table <- renderTable({


Is it because of date?

But the actual app is in ui.R and server.R

It might be the daterangeinput because as a range it has two values, not sure f it has a nice default like only setting start of range if you just pass one value. I'd prefer be explicit and pass a c(d1,d2) to expectupdate for the daterangeinput if you know what I mean?

Hi Nir,

I just removed date from the logic itself and tried with only Tic and Submit. Now also it’s not coming. So date is not the issue here. I think issue with Submit button

hi vinay,
I think it might matter if you want to test a traditional shiny app vs a rmarkdown-shiny thing.


Interactive R markdown documents

Shinytest can be used with interactive R markdown documents that use runtime: shiny (sometimes also referred to as Shiny documents). This includes those that use the flexdashboard package.

Shiny documents have some differences compared to regular Shiny applications, and so the tests are slightly different. For an example of an interactive Rmd with tests, see here

Should we prioritise trying to figure out the markdown case or the shiny app case ?
The link above ("see here") gives some markdown example, but it doesnt feature expectUpdate as an example component, seems more based off snapshotting and visual confirmations...

Hi Nir, Thanks for that. I created app.r (Tradition app) and tried as well. But again error. please refer below. Actually it should give the output but not sure why I am getting error

        numericInput("n", "Number to add", 5),
        actionButton("add", "Add"),
        verbatimTextOutput("sum", placeholder = TRUE)
    function(input, output, session) {
        nums <- numeric()
        c_sum <- eventReactive(input$add, {
            nums <<- c(nums, input$n)
        output$sum <- renderText({
app <- ShinyDriver$new(getwd())
expectUpdate(app, n = 5, add = 1, output = "sum", timeout = 3000)
Error: Updating ‘n’, ‘add’ did not update ‘sum’, or it is taking longer than 3000 ms.

Guess this is a bug kind off thing.

Hi Nir,

Let me know if you need more info from my side

sorry, I got stuck without too. expectUpdate seems to be the least documented shinytest function... I don't know how to make it work. I saw that in their own test scripts they had button clicks represented as 'click' rather than the number which r shiny has. I guess because underthehood shinytest is java heavy
but I tried something like

expectUpdate(app,add="click", output = "sum")

and it still timedout and no effect.
I apologies but I think I'm finished investigating this issue. :frowning:

Hi Nir. No worries. i will try to figure out

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