Skip to contents

datasetServer()

Verify NULL

shiny::testServer(datasetServer, expr = {

  testthat::expect_equal(input$dataset, NULL)
  test_cmt("datasetServer", "dataset$input is NULL")
})
#> Loading required package: shiny
#> 
#>     datasetServer: dataset$input is NULL

Verify input

shiny::testServer(datasetServer, expr = {
  session$setInputs(dataset = "faithful")
  testthat::expect_equal(
    object = input$dataset,
    expected = "faithful")
  test_cmt("datasetServer", "dataset$input")
})
#> 
#>     datasetServer: dataset$input

Verify class() of returned()

class(datasets::airquality)
#> [1] "data.frame"
shiny::testServer(datasetServer, expr = {
  session$setInputs(dataset = "airquality")
  testthat::expect_equal(
    object = class(session$returned()),
    expected = "data.frame")
  test_cmt("datasetServer", "class(session$returned())")
})
#> 
#>     datasetServer: class(session$returned())

Verify class() of returned()

is.matrix(datasets::WorldPhones)
#> [1] TRUE
shiny::testServer(datasetServer, expr = {
  session$setInputs(dataset = "WorldPhones")
  testthat::expect_true(
    object = is.matrix(session$returned()))
  test_cmt("datasetServer", "is.matrix(session$returned())")
})
#> 
#>     datasetServer: is.matrix(session$returned())

Verify typeof() of returned()

typeof(datasets::mtcars)
#> [1] "list"
shiny::testServer(datasetServer, expr = {
  session$setInputs(dataset = "mtcars")
  expect_equal(
    object = typeof(session$returned()),
    expected = typeof(datasets::mtcars))
  test_cmt("datasetServer", "typeof(session$returned())")
})
#> 
#>     datasetServer: typeof(session$returned())

datasetApp()

Check dataset input

ds_app <- datasetApp()
shiny::testServer(app = ds_app, expr = {
  session$setInputs(`dataset-dataset` = "chickwts")
  testthat::expect_equal(
    object = input$`dataset-dataset`,
    expected = "chickwts")
  test_cmt("datasetApp", "input$`dataset-dataset`")
})
#> 
#>     datasetApp: input$`dataset-dataset`

Check class of reactive data()

ds_app <- datasetApp()
shiny::testServer(app = ds_app, expr = {
  session$setInputs(`dataset-dataset` = "chickwts")
  testthat::expect_true(
    object = is.data.frame(data()))
  test_cmt("datasetApp", "is.data.frame(data())")
})
#> 
#>     datasetApp: is.data.frame(data())
ds_app <- datasetApp()
shiny::testServer(app = ds_app, expr = {
  session$setInputs(`dataset-dataset` = "chickwts")
  testthat::expect_equal(
    object = names(data()),
    expected = names(datasets::chickwts))
  test_cmt("datasetApp", "names(data())")
})
#> 
#>     datasetApp: names(data())
ds_app <- datasetApp()
shiny::testServer(app = ds_app, expr = {
  session$setInputs(`dataset-dataset` = "chickwts")
  testthat::expect_equal(
    object = class(output$data),
    expected = "character")
  test_cmt("datasetApp", "class(output$data)")

})
#> 
#>     datasetApp: class(output$data)