| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/test-export.R |
| 3 |
\name{exportTestValues} |
| 4 |
\alias{exportTestValues} |
| 5 |
\title{Register expressions for export in test mode} |
| 6 |
\usage{ |
| 7 |
exportTestValues( |
| 8 |
..., |
| 9 |
quoted_ = FALSE, |
| 10 |
env_ = parent.frame(), |
| 11 |
session_ = getDefaultReactiveDomain() |
| 12 |
) |
| 13 |
} |
| 14 |
\arguments{ |
| 15 |
\item{...}{Named arguments that are quoted or unquoted expressions that will |
| 16 |
be captured and evaluated when snapshot URL is visited.} |
| 17 |
|
| 18 |
\item{quoted_}{Are the expression quoted? Default is \code{FALSE}.} |
| 19 |
|
| 20 |
\item{env_}{The environment in which the expression should be evaluated.} |
| 21 |
|
| 22 |
\item{session_}{A Shiny session object.} |
| 23 |
} |
| 24 |
\description{ |
| 25 |
This function registers expressions that will be evaluated when a test export |
| 26 |
event occurs. These events are triggered by accessing a snapshot URL. |
| 27 |
} |
| 28 |
\details{ |
| 29 |
This function only has an effect if the app is launched in test mode. This is |
| 30 |
done by calling \code{runApp()} with \code{test.mode=TRUE}, or by setting the |
| 31 |
global option \code{shiny.testmode} to \code{TRUE}. |
| 32 |
} |
| 33 |
\examples{ |
| 34 |
## Only run this example in interactive R sessions |
| 35 |
if (interactive()) { |
| 36 |
|
| 37 |
options(shiny.testmode = TRUE) |
| 38 |
|
| 39 |
# This application shows the test snapshot URL; clicking on it will |
| 40 |
# fetch the input, output, and exported values in JSON format. |
| 41 |
shinyApp( |
| 42 |
ui = basicPage( |
| 43 |
h4("Snapshot URL: "), |
| 44 |
uiOutput("url"), |
| 45 |
h4("Current values:"), |
| 46 |
verbatimTextOutput("values"), |
| 47 |
actionButton("inc", "Increment x") |
| 48 |
), |
| 49 |
|
| 50 |
server = function(input, output, session) { |
| 51 |
vals <- reactiveValues(x = 1) |
| 52 |
y <- reactive({ vals$x + 1 }) |
| 53 |
|
| 54 |
observeEvent(input$inc, { |
| 55 |
vals$x <<- vals$x + 1 |
| 56 |
}) |
| 57 |
|
| 58 |
exportTestValues( |
| 59 |
x = vals$x, |
| 60 |
y = y() |
| 61 |
) |
| 62 |
|
| 63 |
output$url <- renderUI({ |
| 64 |
url <- session$getTestSnapshotUrl(format="json") |
| 65 |
a(href = url, url) |
| 66 |
}) |
| 67 |
|
| 68 |
output$values <- renderText({ |
| 69 |
paste0("vals$x: ", vals$x, "\ny: ", y()) |
| 70 |
}) |
| 71 |
} |
| 72 |
) |
| 73 |
} |
| 74 |
} |