Skip to content

Commit

Permalink
Add a test for setInputValue(..., {priority: "event"})
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Sep 17, 2019
1 parent 2e01711 commit 727f0bb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 175-setInputValue/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
library(shiny)

ui <- fluidPage(
includeScript("script.js"),
p("This test exercises Shiny.setInputValue() with different priorities."),
p("The word 'Pass' should appear below within a couple of seconds."),
uiOutput("result")
)

server <- function(input, output, session) {
test_evt_count <- reactiveVal(0)
observeEvent(input$test_evt, {
test_evt_count(test_evt_count() + 1)
})

test_val_count <- reactiveVal(0)
observeEvent(input$test_val, {
test_val_count(test_val_count() + 1)
})

o <- observeEvent(invalidateLater(2000), {
o$destroy()
output$result <- renderUI({
if (identical(test_evt_count(), 5) && identical(test_val_count(), 1)) {
tags$h1(class = "alert alert-success", "Pass")
} else {
tags$h1(class = "alert alert-danger", "fail")
message("test_evt_count() == ", test_evt_count())
message("test_val_count() == ", test_val_count())
}
})
}, ignoreNULL = FALSE, ignoreInit = TRUE)
}

shinyApp(ui, server)
15 changes: 15 additions & 0 deletions 175-setInputValue/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$(function() {
setTimeout(function() {
Shiny.setInputValue("test_evt", 1, {priority: "event"});
Shiny.setInputValue("test_evt", 1, {priority: "event"});
Shiny.setInputValue("test_evt", 1, {priority: "event"});
Shiny.setInputValue("test_evt", 1, {priority: "event"});
Shiny.setInputValue("test_evt", 1, {priority: "event"});

Shiny.setInputValue("test_val", 1, {priority: "immediate"});
Shiny.setInputValue("test_val", 1, {priority: "deferred"});
Shiny.setInputValue("test_val", 1, {priority: "immediate"});
Shiny.setInputValue("test_val", 1);
Shiny.setInputValue("test_val", 1);
}, 1000);
});

0 comments on commit 727f0bb

Please sign in to comment.