I have a simple Shiny app where the user can select a number to filter the iris dataset by Sepal Length:
library(shiny)
ui <- fluidRow(numericInput("num_input", "Sepal Length Greater Than", min = 4.3, value = 6, max = 7.9),
tableOutput("summary"))
server <- function(input, output) {
output$summary <- renderTable(iris %>% filter(Sepal.Length > input$num_input))
}
shinyApp(ui = ui, server = server)
And I'd like to create a unit test to make sure the output table == my expected table
library(shinytest)
library(testthat)
context("Test Sepal Output")
app <- ShinyDriver$new(".")
test_that("Sepal Length filtered by num_output", {
# set num_input to 30
app$setInputs(num_input = 6)
# get text_out
output <- app$getValue(name = "summary")
# create output dataset
test_data <- iris %>%
filter(Sepal.Length > 6)
# ensure it matches the shiny output
expect_true(identical(output, test_data))
})
app$stop()
But this gives me the error: `Error: Test failed: 'Sepal Length filtered by num_output'
- identical(output, test_data) isn't true.`
How are they not identical? I tried running just output and get "could not find function \"%>%\""
What am I missing here? Any help appreciated!