├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── NAMESPACE ├── R └── helloworld.R ├── README.md ├── inst └── sampleapp │ ├── app.R │ └── tests │ ├── mytest-expected │ ├── 001.json │ ├── 001.png │ ├── 002.json │ └── 002.png │ └── mytest.R ├── man └── helloWorldApp.Rd ├── shinytestPackageExample.Rproj └── tests ├── testthat.R └── testthat ├── apps └── helloworld │ ├── app.R │ └── tests │ ├── mytest-expected │ ├── 001.json │ ├── 001.png │ ├── 002.json │ └── 002.png │ └── mytest.R ├── test-app-file.R └── test-app-function.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^shinytestPackageExample\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | sudo: false 5 | cache: packages 6 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: shinytestPackageExample 2 | Version: 1.0 3 | Title: Example package that uses shinytest 4 | Description: Example package that uses shinytest. 5 | Authors@R: person("Chang", "Winston", , "winston@rstudio.com", c("aut", "cre")) 6 | License: Unlimited 7 | Encoding: UTF-8 8 | LazyData: true 9 | ByteCompile: true 10 | RoxygenNote: 6.0.1.9000 11 | Suggests: 12 | testthat, 13 | shinytest 14 | Imports: 15 | shiny 16 | Remotes: 17 | rstudio/shinytest 18 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(helloWorldApp) 4 | import(shiny) 5 | importFrom(graphics,plot) 6 | importFrom(utils,head) 7 | -------------------------------------------------------------------------------- /R/helloworld.R: -------------------------------------------------------------------------------- 1 | #' A Hello World Shiny app 2 | #' 3 | #' @import shiny 4 | #' @importFrom graphics plot 5 | #' @importFrom utils head 6 | #' @export 7 | helloWorldApp <- function() { 8 | utils::data(cars) 9 | shinyApp( 10 | ui = fluidPage( 11 | sliderInput("n", "n", 1, nrow(cars), 10), 12 | plotOutput("plot") 13 | ), 14 | server = function(input, output) { 15 | output$plot <- renderPlot({ 16 | plot(head(cars, input$n), xlim = range(cars[[1]]), ylim = range(cars[[2]])) 17 | }) 18 | } 19 | ) 20 | } 21 | 22 | 23 | # This is needed to make R CMD check happy 24 | globalVariables("cars") 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Travis build status](https://travis-ci.org/rstudio/shinytestPackageExample.svg?branch=master)](https://travis-ci.org/rstudio/shinytestPackageExample) 2 | 3 | Shinytest example package 4 | ========================= 5 | 6 | This is an example R package which uses [shinytest](https://github.com/rstudio/shinytest) to test two types of applications: 7 | 8 | * An application which is in inst/sampleapp/app.R. 9 | * An application which is created by a function, `helloWorldApp()`, instead of being in an app.R or ui.R/server.R. 10 | 11 | For more information, see https://rstudio.github.io/shinytest/articles/package.html. 12 | -------------------------------------------------------------------------------- /inst/sampleapp/app.R: -------------------------------------------------------------------------------- 1 | data(cars) 2 | 3 | shinyApp( 4 | ui = fluidPage( 5 | sliderInput("n", "n", 1, nrow(cars), 10), 6 | plotOutput("plot") 7 | ), 8 | server = function(input, output) { 9 | output$plot <- renderPlot({ 10 | plot(head(cars, input$n), xlim = range(cars[[1]]), ylim = range(cars[[2]])) 11 | }) 12 | } 13 | ) 14 | -------------------------------------------------------------------------------- /inst/sampleapp/tests/mytest-expected/001.json: -------------------------------------------------------------------------------- 1 | { 2 | "input": { 3 | "n": 10 4 | }, 5 | "output": { 6 | "plot": { 7 | "src": "[image data sha1: 4a1fa7f75c292cbfc535c3a3ba9c11803a664eeb]", 8 | "width": 962, 9 | "height": 400, 10 | "coordmap": [ 11 | { 12 | "domain": { 13 | "left": 3.16, 14 | "right": 25.84, 15 | "bottom": -2.72, 16 | "top": 124.72 17 | }, 18 | "range": { 19 | "left": 59.04, 20 | "right": 931.76, 21 | "bottom": 325.56, 22 | "top": 58.04 23 | }, 24 | "log": { 25 | "x": null, 26 | "y": null 27 | }, 28 | "mapping": { 29 | 30 | } 31 | } 32 | ] 33 | } 34 | }, 35 | "export": { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /inst/sampleapp/tests/mytest-expected/001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/shinytestPackageExample/69a1dfe86c4b982832142be7cec42539bb33111c/inst/sampleapp/tests/mytest-expected/001.png -------------------------------------------------------------------------------- /inst/sampleapp/tests/mytest-expected/002.json: -------------------------------------------------------------------------------- 1 | { 2 | "input": { 3 | "n": 41 4 | }, 5 | "output": { 6 | "plot": { 7 | "src": "[image data sha1: 899ffd23aeb939147c2729fac4ee996fc93117cf]", 8 | "width": 962, 9 | "height": 400, 10 | "coordmap": [ 11 | { 12 | "domain": { 13 | "left": 3.16, 14 | "right": 25.84, 15 | "bottom": -2.72, 16 | "top": 124.72 17 | }, 18 | "range": { 19 | "left": 59.04, 20 | "right": 931.76, 21 | "bottom": 325.56, 22 | "top": 58.04 23 | }, 24 | "log": { 25 | "x": null, 26 | "y": null 27 | }, 28 | "mapping": { 29 | 30 | } 31 | } 32 | ] 33 | } 34 | }, 35 | "export": { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /inst/sampleapp/tests/mytest-expected/002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/shinytestPackageExample/69a1dfe86c4b982832142be7cec42539bb33111c/inst/sampleapp/tests/mytest-expected/002.png -------------------------------------------------------------------------------- /inst/sampleapp/tests/mytest.R: -------------------------------------------------------------------------------- 1 | app <- ShinyDriver$new("../") 2 | app$snapshotInit("mytest") 3 | 4 | app$snapshot() 5 | app$setInputs(n = 41) 6 | app$snapshot() 7 | -------------------------------------------------------------------------------- /man/helloWorldApp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helloworld.R 3 | \name{helloWorldApp} 4 | \alias{helloWorldApp} 5 | \title{A Hello World Shiny app} 6 | \usage{ 7 | helloWorldApp() 8 | } 9 | \description{ 10 | A Hello World Shiny app 11 | } 12 | -------------------------------------------------------------------------------- /shinytestPackageExample.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(shinytestPackageExample) 3 | 4 | test_check("shinytestPackageExample") 5 | -------------------------------------------------------------------------------- /tests/testthat/apps/helloworld/app.R: -------------------------------------------------------------------------------- 1 | library(shinytestPackageExample) 2 | 3 | helloWorldApp() 4 | -------------------------------------------------------------------------------- /tests/testthat/apps/helloworld/tests/mytest-expected/001.json: -------------------------------------------------------------------------------- 1 | { 2 | "input": { 3 | "n": 10 4 | }, 5 | "output": { 6 | "plot": { 7 | "src": "[image data sha1: 4a1fa7f75c292cbfc535c3a3ba9c11803a664eeb]", 8 | "width": 962, 9 | "height": 400, 10 | "coordmap": [ 11 | { 12 | "domain": { 13 | "left": 3.16, 14 | "right": 25.84, 15 | "bottom": -2.72, 16 | "top": 124.72 17 | }, 18 | "range": { 19 | "left": 59.04, 20 | "right": 931.76, 21 | "bottom": 325.56, 22 | "top": 58.04 23 | }, 24 | "log": { 25 | "x": null, 26 | "y": null 27 | }, 28 | "mapping": { 29 | 30 | } 31 | } 32 | ] 33 | } 34 | }, 35 | "export": { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/testthat/apps/helloworld/tests/mytest-expected/001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/shinytestPackageExample/69a1dfe86c4b982832142be7cec42539bb33111c/tests/testthat/apps/helloworld/tests/mytest-expected/001.png -------------------------------------------------------------------------------- /tests/testthat/apps/helloworld/tests/mytest-expected/002.json: -------------------------------------------------------------------------------- 1 | { 2 | "input": { 3 | "n": 41 4 | }, 5 | "output": { 6 | "plot": { 7 | "src": "[image data sha1: 899ffd23aeb939147c2729fac4ee996fc93117cf]", 8 | "width": 962, 9 | "height": 400, 10 | "coordmap": [ 11 | { 12 | "domain": { 13 | "left": 3.16, 14 | "right": 25.84, 15 | "bottom": -2.72, 16 | "top": 124.72 17 | }, 18 | "range": { 19 | "left": 59.04, 20 | "right": 931.76, 21 | "bottom": 325.56, 22 | "top": 58.04 23 | }, 24 | "log": { 25 | "x": null, 26 | "y": null 27 | }, 28 | "mapping": { 29 | 30 | } 31 | } 32 | ] 33 | } 34 | }, 35 | "export": { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/testthat/apps/helloworld/tests/mytest-expected/002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstudio/shinytestPackageExample/69a1dfe86c4b982832142be7cec42539bb33111c/tests/testthat/apps/helloworld/tests/mytest-expected/002.png -------------------------------------------------------------------------------- /tests/testthat/apps/helloworld/tests/mytest.R: -------------------------------------------------------------------------------- 1 | app <- ShinyDriver$new("../") 2 | app$snapshotInit("mytest") 3 | 4 | app$snapshot() 5 | app$setInputs(n = 41) 6 | app$snapshot() 7 | -------------------------------------------------------------------------------- /tests/testthat/test-app-file.R: -------------------------------------------------------------------------------- 1 | context("app-file") 2 | # This file is for testing the applications in the inst/ directory. 3 | 4 | library(shinytest) 5 | 6 | test_that("sampleapp works", { 7 | # Don't run these tests on the CRAN build servers 8 | skip_on_cran() 9 | 10 | # Use compareImages=FALSE because the expected image screenshots were created 11 | # on a Mac, and they will differ from screenshots taken on the CI platform, 12 | # which runs on Linux. 13 | appdir <- system.file(package = "shinytestPackageExample", "sampleapp") 14 | expect_pass(testApp(appdir, compareImages = FALSE)) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-app-function.R: -------------------------------------------------------------------------------- 1 | context("app-function") 2 | # This file is for testing the applications in the apps/ directory. 3 | 4 | library(shinytest) 5 | 6 | test_that("helloWorldApp() works", { 7 | # Don't run these tests on the CRAN build servers 8 | skip_on_cran() 9 | 10 | # Use compareImages=FALSE because the expected image screenshots were created 11 | # on a Mac, and they will differ from screenshots taken on the CI platform, 12 | # which runs on Linux. 13 | expect_pass(testApp("apps/helloworld/", compareImages = FALSE)) 14 | }) 15 | --------------------------------------------------------------------------------