Test standalone shiny app for a single shiny module

131 views Asked by At

Is there an easy way to test if a standalone shiny app, built for a single module, is running (also to get more code coverage)?

To give some background, I've built a shiny app consisting of several modules. For each of the modules, I've built a standalone app to test its functionality in the web browser.

I test the server and UI parts of the module separately, but I am looking for an easy way to test if the standalone app is running. Testing with the shinytest R-package is probably feasible, but here I don't really now what to test against as the standalone app not even has input arguments etc.

Shiny app built with modules:

library("shiny")

featureOutput <- function(id) {
  plotOutput(NS(id, "plot"))
}

featureServer <- function(id, value) {
  moduleServer(id, function(input, output, session) {
    output$plot <- renderPlot({
      graphics::hist(value())
    }, res = 96)
  })
}

featureApp <- function() {
  ui <- fluidPage(
    featureOutput("test")
  )

  server <- function(input, output, session) {
    dat <- reactive({datasets::mtcars$disp})
    featureServer("test", dat)
  }

  shinyApp(ui, server)
}

Tests with testthat:

library("testthat")

test_that("Test module", {
  testServer(featureServer, args = list(value = reactive(cars$speed)), {
    testthat::expect_output(str(output$plot), NULL)
  })

  expect_snapshot(featureOutput("x"))
})
0

There are 0 answers