## ------------------------------------------------
## Method `AppDriver$new`
## ------------------------------------------------
if (FALSE) {
# Create an AppDriver from the Shiny app in the current directory
app <- AppDriver()
# Create an AppDriver object from a different Shiny app directory
example_app <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver(example_app)
# Expect consistent inital values
app$expect_values()
}
## ------------------------------------------------
## Method `AppDriver$view`
## ------------------------------------------------
if (FALSE) {
# Open app in Chrome
app$view()
}
## ------------------------------------------------
## Method `AppDriver$click`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/07_widgets", package = "shiny")
app <- AppDriver$new(app_path)
tmpfile <- write.csv(cars, "cars.csv")
app$upload_file(file1 = tmpfile)
cat(app$get_text("#view"))
app$set_inputs(dataset = "cars", obs = 6)
app$click("update")
cat(app$get_text("#view"))
}
## ------------------------------------------------
## Method `AppDriver$set_inputs`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/07_widgets", package = "shiny")
app <- AppDriver$new(app_path)
cat(app$get_text("#view"))
app$set_inputs(dataset = "cars", obs = 6)
app$click("update")
cat(app$get_text("#view"))
}
## ------------------------------------------------
## Method `AppDriver$upload_file`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/09_upload", package = "shiny")
app <- AppDriver$new(app_path)
# Save example file
tmpfile <- tempfile(fileext = ".csv")
write.csv(cars, tmpfile, row.names = FALSE)
# Upload file to input named: file1
app$upload_file(file1 = tmpfile)
}
## ------------------------------------------------
## Method `AppDriver$expect_values`
## ------------------------------------------------
if (FALSE) {
library(shiny)
shiny_app <- shinyApp(
fluidPage(
h1("Pythagorean theorem"),
numericInput("A", "A", 3),
numericInput("B", "B", 4),
verbatimTextOutput("C"),
),
function(input, output) {
a_squared <- reactive({ req(input$A); input$A * input$A })
b_squared <- reactive({ req(input$B); input$B * input$B })
c_squared <- reactive({ a_squared() + b_squared() })
c_value <- reactive({ sqrt(c_squared()) })
output$C <- renderText({ c_value() })
exportTestValues(
a_squared = { a_squared() },
b_squared = { b_squared() },
c_squared = { c_squared() }
)
}
)
app <- AppDriver$new(shiny_app)
# Snapshot all known values
app$expect_values()
# Snapshot only `export` values
app$expect_values(export = TRUE)
# Snapshot values `"A"` from `input` and `"C"` from `output`
app$expect_values(input = "A", output = "C")
}
## ------------------------------------------------
## Method `AppDriver$get_value`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/04_mpg", package = "shiny")
app <- AppDriver$new(app_path)
# Retrieve a single value
app$get_value(output = "caption")
#> [1] "mpg ~ cyl"
# Equivalent code using `$get_values()`
app$get_values(output = "caption")$output$caption
#> [1] "mpg ~ cyl"
}
## ------------------------------------------------
## Method `AppDriver$get_values`
## ------------------------------------------------
if (FALSE) {
library(shiny)
shiny_app <- shinyApp(
fluidPage(
h1("Pythagorean theorem"),
numericInput("A", "A", 3),
numericInput("B", "B", 4),
verbatimTextOutput("C"),
),
function(input, output) {
a_squared <- reactive({ req(input$A); input$A * input$A })
b_squared <- reactive({ req(input$B); input$B * input$B })
c_squared <- reactive({ a_squared() + b_squared() })
c_value <- reactive({ sqrt(c_squared()) })
output$C <- renderText({ c_value() })
exportTestValues(
a_squared = { a_squared() },
b_squared = { b_squared() },
c_squared = { c_squared() }
)
}
)
app <- AppDriver$new(shiny_app)
# Show all known values
str(app$get_values())
#> List of 3
#> $ input :List of 2
#> ..$ A: int 3
#> ..$ B: int 4
#> $ output:List of 1
#> ..$ C: chr "5"
#> $ export:List of 3
#> ..$ a_squared: int 9
#> ..$ b_squared: int 16
#> ..$ c_squared: int 25
# Get only `export` values
str(app$get_values(export = TRUE))
#> List of 1
#> $ export:List of 3
#> ..$ a_squared: int 9
#> ..$ b_squared: int 16
#> ..$ c_squared: int 25
# Get values `"A"` from `input` and `"C"` from `output`
str(app$get_values(input = "A", output = "C"))
#> List of 2
#> $ input :List of 1
#> ..$ A: int 3
#> $ output:List of 1
#> ..$ C: chr "5"
}
## ------------------------------------------------
## Method `AppDriver$expect_download`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/10_download", package = "shiny")
app <- AppDriver$new(app_path)
# Save snapshot of rock.csv as 001.download
# Save snapshot value of `rock.csv` to capture default file name
app$expect_download("downloadData", compare = testthat::compare_file_text)
}
## ------------------------------------------------
## Method `AppDriver$get_download`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/10_download", package = "shiny")
app <- AppDriver$new(app_path)
# Get rock.csv as a tempfile
app$get_download("downloadData")
#> [1] "/TEMP/PATH/rock.csv"
# Get rock.csv as a "./myfile.csv"
app$get_download("downloadData", filename = "./myfile.csv")
#> [1] "./myfile.csv"
}
## ------------------------------------------------
## Method `AppDriver$expect_text`
## ------------------------------------------------
if (FALSE) {
hello_app <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(hello_app)
# Make a snapshot of `"Hello Shiny!"`
app$expect_text("h2")
}
## ------------------------------------------------
## Method `AppDriver$get_text`
## ------------------------------------------------
if (FALSE) {
hello_app <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(hello_app)
app$get_text("h2")
#> [1] "Hello Shiny!"
}
## ------------------------------------------------
## Method `AppDriver$expect_html`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/04_mpg", package = "shiny")
app <- AppDriver$new(app_path)
# Save a snapshot of the `caption` output
app$expect_html("#caption")
}
## ------------------------------------------------
## Method `AppDriver$get_html`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/03_reactivity", package = "shiny")
app <- AppDriver$new(app_path, check_names = FALSE)
app$set_inputs(caption = "Custom value!")
cat(app$get_html(".shiny-input-container")[1])
#>
#> Caption:
#>
#>
## ^^ No update to the DOM of `caption`
}
## ------------------------------------------------
## Method `AppDriver$expect_js`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/07_widgets", package = "shiny")
app <- AppDriver$new(app_path)
# Track how many clicks are given to `#update` button
app$run_js("
window.test_counter = 0;
$('#update').click(() => window.test_counter++);
")
app$set_inputs(obs = 20)
# Click the update button, incrementing the counter
app$click("update")
# Save a snapshot of number of clicks (1)
app$expect_js("window.test_counter;")
}
## ------------------------------------------------
## Method `AppDriver$get_js`
## ------------------------------------------------
if (FALSE) {
library(shiny)
shiny_app <- shinyApp(h1("Empty App"), function(input, output) { })
app <- AppDriver$new(shiny_app)
# Execute JavaScript code in the app's browser
app$get_js("1 + 1;")
#> [1] 2
# Execute a JavaScript Promise. Return the resolved value.
app$get_js("
new Promise((resolve) => {
setTimeout(() => resolve(1 + 1), 1000)
}).
then((value) => value + 1);
")
#> [1] 3
# With escaped arguments
loc_field <- "hostname"
js_txt <- paste0("window.location[", jsonlite::toJSON(loc_field, auto_unbox = TRUE), "]")
app$get_js(js_txt)
#> [1] "127.0.0.1"
# With `glue::glue()`
js_txt <- glue::glue_data(
lapply(
list(x = 40, y = 2),
jsonlite::toJSON,
auto_unbox = TRUE
),
.open = "<", .close = ">",
"let answer = function(a, b) {\n",
" return a + b;\n",
"};\n",
"answer(, );\n"
)
app$get_js(js_txt)
#> [1] 42
}
## ------------------------------------------------
## Method `AppDriver$run_js`
## ------------------------------------------------
if (FALSE) {
library(shiny)
shiny_app <- shinyApp(h1("Empty App"), function(input, output) { })
app <- AppDriver$new(shiny_app)
# Get JavaScript answer from the app's browser
app$get_js("1 + 1")
#> [1] 2
# Execute JavaScript code in the app's browser
app$run_js("1 + 1")
# (Returns `app` invisibly)
# With escaped arguments
loc_field <- "hostname"
js_txt <- paste0("window.location[", jsonlite::toJSON(loc_field, auto_unbox = TRUE), "]")
app$run_js(js_txt)
app$get_js(js_txt)
#> [1] "127.0.0.1"
}
## ------------------------------------------------
## Method `AppDriver$expect_screenshot`
## ------------------------------------------------
if (FALSE) {
# These example lines should be performed in a `./tests/testthat`
# test file so that snapshot files can be properly saved
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path, variant = platform_variant())
# Expect a full size screenshot to be pixel perfect
app$expect_screenshot()
# Images are brittle when containing plots
app$expect_screenshot(selector = "#distPlot")
# Test with more threshold in pixel value differences
# Helps with rounded corners
app$expect_screenshot(threshold = 10)
# Equivalent expectations
app$expect_screenshot() # default
app$expect_screenshot(threshold = NULL)
app$expect_screenshot(compare = testthat::compare_file_binary)
expect_snapshot_file(
app$get_screenshot(),
variant = app$get_variant(),
compare = testthat::compare_file_binary
)
# Equivalent expectations
app$expect_screenshot(threshold = 3, kernel_size = 5)
app$expect_screenshot(compare = function(old, new) {
compare_screenshot_threshold(
old, new,
threshold = 3,
kernel_size = 5
)
})
expect_screenshot_file(
app$get_screenshot(),
variant = app$get_variant(),
compare = function(old, new) {
compare_screenshot_threshold(
old, new,
threshold = 3,
kernel_size = 5
)
}
)
# Take a screenshot of the entire scrollable area
app$expect_screenshot()
app$expect_screenshot(selector = "scrollable_area")
## Take a screenshot of the current viewport
# Shrink the window to be smaller than the app
app$set_window_size(400, 500)
# Scroll the viewport just a bit
app$run_js("window.scroll(30, 70)")
# Take screenshot of browser viewport
app$expect_screenshot(selector = "viewport")
}
## ------------------------------------------------
## Method `AppDriver$get_screenshot`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path)
# Display in graphics device
app$get_screenshot()
# Update bins then display `"disPlot"` in graphics device
app$set_inputs(bins = 10)
app$get_screenshot(selector = "#distPlot")
# Save screenshot to file and view it
tmpfile <- tempfile(fileext = ".png")
app$get_screenshot(tmpfile)
showimage::show_image(tmpfile)
}
## ------------------------------------------------
## Method `AppDriver$wait_for_idle`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path)
pre_value <- app$get_value(output = "distPlot")
# Update bins value
app$set_inputs(bins = 10, wait_ = FALSE)
middle_value <- app$get_value(output = "distPlot")
app$wait_for_idle()
post_value <- app$get_value(output = "distPlot")
# No guarantee that these values are different
identical(pre_value, middle_value)
# Will not be equal
identical(pre_value, post_value)
# ---------------------
## Change the screen size to trigger a plot update
pre_value <- app$get_value(output = "distPlot")
app$set_window_size(height = 1080, width = 1920, wait = FALSE)
middle_value <- app$get_value(output = "distPlot")
app$wait_for_idle()
post_value <- app$get_value(output = "distPlot")
# No guarantee that these values are different
identical(pre_value, middle_value)
# Will not be equal
identical(pre_value, post_value)
}
## ------------------------------------------------
## Method `AppDriver$wait_for_value`
## ------------------------------------------------
if (FALSE) {
library(shiny)
shiny_app <- shinyApp(
fluidPage(
h1("Dynamic output"),
actionButton("display", "Display UI"),
uiOutput("dym1"),
),
function(input, output) {
output$dym1 <- renderUI({
req(input$display)
Sys.sleep(runif(1, max = 2)) # Artificial calculations
tagList(
sliderInput("slider1", "Slider #1", 0, 100, 25),
uiOutput("dym2")
)
})
output$dym2 <- renderUI({
Sys.sleep(runif(1, max = 2)) # Artificial calculations
tagList(
sliderInput("slider2", "Slider #2", 0, 100, 50),
"Total:", verbatimTextOutput("total")
)
})
output$total <- renderText({
req(input$slider1, input$slider2)
input$slider1 + input$slider2
})
}
)
app <- AppDriver$new(shiny_app)
# Create UI / output values
app$click("display")
# Wait for total to be calculated (or have a non-NULL value)
new_total_value <- app$wait_for_value(output = "total")
#> [1] "75"
app$get_value(output = "total")
#> [1] "75"
}
## ------------------------------------------------
## Method `AppDriver$wait_for_js`
## ------------------------------------------------
if (FALSE) {
shiny_app <- shinyApp(h1("Empty App"), function(input, output) { })
app <- AppDriver$new(shiny_app)
# Contrived example:
# Wait until `Date.now()` returns a number that ends in a 5. (0 - 10 seconds)
system.time(
app$wait_for_js("Math.floor((Date.now() / 1000) % 10) == 5;")
)
## A second example where we run the contents of a JavaScript file
## and use the result to wait for a condition
app$run_js(file = "complicated_file.js")
app$wait_for_js("complicated_condition();")
}
## ------------------------------------------------
## Method `AppDriver$expect_unique_names`
## ------------------------------------------------
if (FALSE) {
shiny_app <- shinyApp(
ui = fluidPage(
# Duplicate input IDs: `"text"`
textInput("text", "Text 1"),
textInput("text", "Text 2")
),
server = function(input, output) {
# empty
}
)
# Initial checking for unique names (default behavior)
app <- AppDriver$new(shiny_app, check_names = TRUE)
#> Warning:
#> ! Shiny inputs should have unique HTML id values.
#> i The following HTML id values are not unique:
#> • text
app$stop()
# Manually assert that all names are unique
app <- AppDriver$new(shiny_app, check_names = FALSE)
app$expect_unique_names()
#> Error: `app_check_unique_names(self, private)` threw an unexpected warning.
#> Message: ! Shiny inputs should have unique HTML id values.
#> i The following HTML id values are not unique:
#> • text
#> Class: rlang_warning/warning/condition
app$stop()
}
## ------------------------------------------------
## Method `AppDriver$get_dir`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path)
identical(app$get_dir(), app_path)
#> [1] TRUE
}
## ------------------------------------------------
## Method `AppDriver$get_url`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path)
browseURL(app$get_url())
}
## ------------------------------------------------
## Method `AppDriver$get_window_size`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path)
app$get_window_size()
#> $width
#> [1] 992
#>
#> $height
#> [1] 1323
}
## ------------------------------------------------
## Method `AppDriver$set_window_size`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
# Set init window size
app <- AppDriver$new(app_path, height = 1400, width = 1000)
app$get_window_size()
#> $width
#> [1] 1000
#>
#> $height
#> [1] 1400
# Manually set the window size
app$set_window_size(height = 1080, width = 1920)
app$get_window_size()
#> $width
#> [1] 1920
#>
#> $height
#> [1] 1080
}
## ------------------------------------------------
## Method `AppDriver$get_chromote_session`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path)
b <- app$get_chromote_session()
b$Runtime$evaluate("1 + 1")
#> $result
#> $result$type
#> [1] "number"
#>
#> $result$value
#> [1] 2
#>
#> $result$description
#> [1] "2"
}
## ------------------------------------------------
## Method `AppDriver$get_variant`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path)
app$get_variant()
#> NULL
app <- AppDriver$new(app_path, variant = platform_variant())
app$get_variant()
#> [1] "mac-4.1"
}
## ------------------------------------------------
## Method `AppDriver$get_logs`
## ------------------------------------------------
if (FALSE) {
app1 <- AppDriver$new(system.file("examples/01_hello", package = "shiny"))
app1$get_logs()
#> {shinytest2} R info 10:00:28.86 Start AppDriver initialization
#> {shinytest2} R info 10:00:28.86 Starting Shiny app
#> {shinytest2} R info 10:00:29.76 Creating new ChromoteSession
#> {shinytest2} R info 10:00:30.56 Navigating to Shiny app
#> {shinytest2} R info 10:00:30.70 Injecting shiny-tracer.js
#> {chromote} JS info 10:00:30.75 shinytest2; jQuery found
#> {chromote} JS info 10:00:30.77 shinytest2; Waiting for shiny session to connect
#> {chromote} JS info 10:00:30.77 shinytest2; Loaded
#> {shinytest2} R info 10:00:30.77 Waiting for Shiny to become ready
#> {chromote} JS info 10:00:30.90 shinytest2; Connected
#> {chromote} JS info 10:00:30.95 shinytest2; shiny:busy
#> {shinytest2} R info 10:00:30.98 Waiting for Shiny to become idle for 200ms within 15000ms
#> {chromote} JS info 10:00:30.98 shinytest2; Waiting for Shiny to be stable
#> {chromote} JS info 10:00:31.37 shinytest2; shiny:idle
#> {chromote} JS info 10:00:31.38 shinytest2; shiny:value distPlot
#> {chromote} JS info 10:00:31.57 shinytest2; Shiny has been idle for 200ms
#> {shinytest2} R info 10:00:31.57 Shiny app started
#> {shiny} R stderr ----------- Loading required package: shiny
#> {shiny} R stderr ----------- Running application in test mode.
#> {shiny} R stderr -----------
#> {shiny} R stderr ----------- Listening on http://127.0.0.1:4679
# To capture all websocket traffic, set `options = list(shiny.trace = TRUE)`
app2 <- AppDriver$new(
system.file("examples/01_hello", package = "shiny"),
options = list(shiny.trace = TRUE)
)
app2$get_logs()
## (All WebSocket messages have been replaced with `WEBSOCKET_MSG` in example below)
#> {shinytest2} R info 10:01:57.49 Start AppDriver initialization
#> {shinytest2} R info 10:01:57.50 Starting Shiny app
#> {shinytest2} R info 10:01:58.20 Creating new ChromoteSession
#> {shinytest2} R info 10:01:58.35 Navigating to Shiny app
#> {shinytest2} R info 10:01:58.47 Injecting shiny-tracer.js
#> {chromote} JS info 10:01:58.49 shinytest2; jQuery not found
#> {chromote} JS info 10:01:58.49 shinytest2; Loaded
#> {shinytest2} R info 10:01:58.50 Waiting for Shiny to become ready
#> {chromote} JS info 10:01:58.55 shinytest2; jQuery found
#> {chromote} JS info 10:01:58.55 shinytest2; Waiting for shiny session to connect
#> {chromote} JS websocket 10:01:58.64 send WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.67 recv WEBSOCKET_MSG
#> {chromote} JS info 10:01:58.67 shinytest2; Connected
#> {chromote} JS websocket 10:01:58.71 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.72 recv WEBSOCKET_MSG
#> {chromote} JS info 10:01:58.72 shinytest2; shiny:busy
#> {chromote} JS websocket 10:01:58.73 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.73 recv WEBSOCKET_MSG
#> {shinytest2} R info 10:01:58.75 Waiting for Shiny to become idle for 200ms within 15000ms
#> {chromote} JS info 10:01:58.75 shinytest2; Waiting for Shiny to be stable
#> {chromote} JS websocket 10:01:58.81 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.81 recv WEBSOCKET_MSG
#> {chromote} JS info 10:01:58.81 shinytest2; shiny:idle
#> {chromote} JS websocket 10:01:58.82 recv WEBSOCKET_MSG
#> {chromote} JS info 10:01:58.82 shinytest2; shiny:value distPlot
#> {chromote} JS info 10:01:59.01 shinytest2; Shiny has been idle for 200ms
#> {shinytest2} R info 10:01:59.01 Shiny app started
#> {shiny} R stderr ----------- Loading required package: shiny
#> {shiny} R stderr ----------- Running application in test mode.
#> {shiny} R stderr -----------
#> {shiny} R stderr ----------- Listening on http://127.0.0.1:4560
#> {shiny} R stderr ----------- SEND {"config":{"workerId":"","sessionId"|truncated
#> {shiny} R stderr ----------- RECV {"method":"init","data":{"bins":30,|truncated
#> {shiny} R stderr ----------- SEND {"custom":{"showcase-src":{"srcref":|truncated
#> {shiny} R stderr ----------- SEND {"busy":"busy"}
#> {shiny} R stderr ----------- SEND {"custom":{"showcase-src":{"srcref":|truncated
#> {shiny} R stderr ----------- SEND {"recalculating":{"name":"distPlot",|truncated
#> {shiny} R stderr ----------- SEND {"recalculating":{"name":"distPlot",|truncated
#> {shiny} R stderr ----------- SEND {"busy":"idle"}
#> {shiny} R stderr ----------- SEND {"errors":{},"values":{"distPlot":|truncated
# The log that is returned is a `data.frame()`.
log <- app2$get_logs()
tibble::glimpse(log)
#> Rows: 43
#> Columns: 5
#> $ workerid NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ timestamp 2022-09-19 10:01:57, 2022-09-19 10:01:57, 2022-09-19 10:01:58, 2022…
#> $ location "shinytest2", "shinytest2", "shinytest2", "shinytest2", "shinytest2"…
#> $ level "info", "info", "info", "info", "info", "info", "info", "info", "inf…
#> $ message "Start AppDriver initialization", "Starting Shiny app", "Creating ne…
#> $ workerid NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ timestamp 2022-03-16 11:09:57, 2022-03-16 11:09:57, 2022-03-16 11:09:…
#> $ location "shinytest2", "shinytest2", "shinytest2", "shinytest2", "shi…
#> $ level "info", "info", "info", "info", "info", "info", "info", "inf…
#> $ message "Start AppDriver initialization", "Starting Shiny app", "Cre…
# It may be filtered to find desired logs
subset(log, level == "websocket")
## (All WebSocket messages have been replaced with `WEBSOCKET_MSG` in example below)
#> {chromote} JS websocket 10:01:58.64 send WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.67 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.71 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.72 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.73 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.73 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.81 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.81 recv WEBSOCKET_MSG
#> {chromote} JS websocket 10:01:58.82 recv WEBSOCKET_MSG
}
## ------------------------------------------------
## Method `AppDriver$log_message`
## ------------------------------------------------
if (FALSE) {
app_path <- system.file("examples/01_hello", package = "shiny")
app <- AppDriver$new(app_path)
app$log_message("Setting bins to smaller value")
app$set_inputs(bins = 10)
app$get_logs()
}
## ------------------------------------------------
## Method `AppDriver$stop`
## ------------------------------------------------
if (FALSE) {
rlang::check_installed("reactlog")
library(shiny)
shiny_app <- shinyApp(
ui = fluidPage(
actionButton("button", "Stop app and return Reactlog"),
"Click count:", textOutput("count")
),
server = function(input, output) {
output$count <- renderText({ input$button })
observe({
req(input$button)
stopApp(shiny::reactlog())
})
}
)
app <- AppDriver$new(
shiny_app,
# Enable reactlog in background R session
options = list(shiny.reactlog = TRUE)
)
app$click("button")
rlog <- app$stop()
str(head(rlog, 2))
#> List of 2
#> $ :List of 7
#> ..$ action : chr "define"
#> ..$ reactId: chr "r3"
#> ..$ label : chr "Theme Counter"
#> ..$ type : chr "reactiveVal"
#> ..$ value : chr " num 0"
#> ..$ session: chr "bdc7417f2fc8c84fc05c9518e36fdc44"
#> ..$ time : num 1.65e+09
#> $ :List of 7
#> ..$ action : chr "define"
#> ..$ reactId: chr "r4"
#> ..$ label : chr "output$count"
#> .. ..- attr(*, "srcref")= int [1:6] 7 32 7 45 32 45
#> .. ..- attr(*, "srcfile")= chr ""
#> ..$ type : chr "observer"
#> ..$ value : chr " NULL"
#> ..$ session: chr "bdc7417f2fc8c84fc05c9518e36fdc44"
#> ..$ time : num 1.65e+09
}
Run the code above in your browser using DataLab