Nothing
test_that("app_check passes for valid R shiny app", {
# app_check resolves the default shinylive strategy and detects R deps,
# which require the shinylive and renv Suggested packages.
skip_if_not(r_shinylive_available(), "shinylive not available")
skip_if_not_installed("renv")
local_no_electron_lookup()
tmpdir <- tempfile()
dir.create(tmpdir)
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(tmpdir, "app.R"))
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE)
result <- app_check(tmpdir, verbose = FALSE)
expect_true(result$pass)
expect_length(result$errors, 0)
})
test_that("app_check fails for missing app files", {
local_no_electron_lookup()
tmpdir <- tempfile()
dir.create(tmpdir)
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE)
result <- app_check(tmpdir, verbose = FALSE)
expect_false(result$pass)
expect_true(any(grepl("app.R|server.R", result$errors)))
})
test_that("app_check fails for nonexistent directory", {
local_no_electron_lookup()
result <- app_check("/nonexistent/path", verbose = FALSE)
expect_false(result$pass)
expect_true(any(grepl("does not exist", result$errors)))
})
test_that("app_check validates Python app structure", {
local_no_electron_lookup()
tmpdir <- tempfile()
dir.create(tmpdir)
writeLines("from shiny import App", file.path(tmpdir, "app.py"))
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE)
# Warns about missing requirements.txt -- expected since we only test app structure
expect_warning(
result <- app_check(tmpdir, app_type = "py-shiny", verbose = FALSE),
"requirements.txt"
)
expect_false(any(grepl("app.py", result$errors)))
})
test_that("app_check warns about missing icon", {
local_no_electron_lookup()
tmpdir <- tempfile()
dir.create(tmpdir)
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(tmpdir, "app.R"))
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE)
result <- app_check(tmpdir, verbose = FALSE)
expect_true(any(grepl("icon|Icon", result$info)))
})
test_that("app_check detects dependencies", {
skip_if_not_installed("renv")
local_no_electron_lookup()
tmpdir <- tempfile()
dir.create(tmpdir)
writeLines(c("library(shiny)", "library(ggplot2)"),
file.path(tmpdir, "app.R"))
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE)
result <- app_check(tmpdir, verbose = FALSE)
expect_true(any(grepl("shiny|ggplot2", result$info)))
})
test_that("app_check surfaces a config parse error as a warning", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny); shinyApp(fluidPage(), function(i,o){})", file.path(appdir, "app.R"))
writeLines("build: : : not yaml", file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_true(any(grepl("Config error", unlist(res$warnings))))
})
test_that("app_check fails for installer settings that export() rejects", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("installer:", " allow_to_change_installation_directory: true"),
file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_false(res$pass)
expect_true(any(grepl("Config error", res$errors)))
expect_false(any(grepl("Config error", res$warnings)))
})
test_that("app_check reports a quoted installer flag as a warning", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("installer:", " one_click: \"false\""),
file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_true(any(grepl("installer.one_click", res$warnings, fixed = TRUE)))
expect_false(any(grepl("installer.one_click", res$errors, fixed = TRUE)))
})
test_that("app_check fails when the installer license file is missing", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("installer:", " license_file: LICENSE.txt"),
file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_false(res$pass)
expect_true(any(grepl("License file not found", res$errors)))
# The path is relative to the app directory, as in export().
writeLines("Terms of use", file.path(appdir, "LICENSE.txt"))
res <- app_check(appdir, verbose = FALSE)
expect_false(any(grepl("License file", res$errors)))
})
test_that("app_check fails on an app slug that export() rejects", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("app:", " slug: Bad Slug"), file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_false(res$pass)
expect_true(any(grepl("app.slug", res$errors, fixed = TRUE)))
})
test_that("app_check checks installer text for a $ like export()", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("app:", " description: Costs $5 a month"),
file.path(appdir, "_shinyelectron.yml"))
# A Windows build stops on it; other builds only warn.
res <- app_check(appdir, platform = "win", verbose = FALSE)
expect_false(res$pass)
expect_true(any(grepl("app.description", res$errors, fixed = TRUE)))
res <- app_check(appdir, platform = "mac", verbose = FALSE)
expect_false(any(grepl("app.description", res$errors, fixed = TRUE)))
expect_true(any(grepl("app.description", res$warnings, fixed = TRUE)))
})
test_that("app_check reports a bundled build for several targets like export()", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("build:", " runtime_strategy: bundled", " architectures: [x64, arm64]"),
file.path(appdir, "_shinyelectron.yml"))
local_mocked_bindings(resolve_app_dependencies = function(...) NULL)
res <- app_check(appdir, verbose = FALSE)
expect_false(res$pass)
expect_true(any(grepl("build.architectures", res$errors, fixed = TRUE)))
# One architecture is one target.
writeLines(c("build:", " runtime_strategy: bundled", " architectures: [x64]"),
file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_false(any(grepl("build.architectures", res$errors, fixed = TRUE)))
})
test_that("app_check reports a macOS target off macOS like export()", {
local_no_electron_lookup()
local_mocked_bindings(detect_current_platform = function() "linux")
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("build:", " platforms: [mac]"),
file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_false(res$pass)
expect_true(any(grepl("Cannot build the", res$errors, fixed = TRUE) &
grepl("build.platforms", res$errors, fixed = TRUE)))
# The platform argument overrides the list, as in export().
res <- app_check(appdir, platform = "linux", verbose = FALSE)
expect_false(any(grepl("Cannot build the", res$errors, fixed = TRUE)))
# An invalid platform argument stops export(), so it is an error here.
res <- app_check(appdir, platform = "windows", verbose = FALSE)
expect_true(any(grepl("Invalid platform", res$errors, fixed = TRUE)))
})
test_that("app_check still reports a $ in installer text after another warning", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("app:", " description: Costs $5 a month"),
file.path(appdir, "_shinyelectron.yml"))
real_app_metadata <- app_metadata
local_mocked_bindings(app_metadata = function(config) {
warning("metadata warning")
real_app_metadata(config)
})
res <- app_check(appdir, platform = "win", verbose = FALSE)
expect_false(res$pass)
expect_true(any(grepl("app.description", res$errors, fixed = TRUE)))
expect_true("metadata warning" %in% res$warnings)
})
test_that("app_check reports every config warning, also before a config error", {
local_no_electron_lookup()
appdir <- withr::local_tempdir()
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
writeLines(c("window:", " widht: 900", "installer:", " per_machine: \"yes\""),
file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_true(any(grepl("window.widht", res$warnings, fixed = TRUE)))
expect_true(any(grepl("installer.per_machine", res$warnings, fixed = TRUE)))
# The quoted flag warns before the setting it belongs to stops the build.
writeLines(c("installer:", " one_click: \"true\"",
" allow_to_change_installation_directory: true"),
file.path(appdir, "_shinyelectron.yml"))
res <- app_check(appdir, verbose = FALSE)
expect_true(any(grepl("installer.one_click", res$warnings, fixed = TRUE)))
expect_true(any(grepl("Config error", res$errors, fixed = TRUE)))
})
test_that("catch_conditions keeps every warning, including those before an error", {
res <- catch_conditions({
warning("first")
warning("second")
"done"
})
expect_equal(res$value, "done")
expect_null(res$error)
expect_equal(res$warnings, c("first", "second"))
res <- catch_conditions({
warning("before")
stop("failed")
})
expect_null(res$value)
expect_equal(conditionMessage(res$error), "failed")
expect_equal(res$warnings, "before")
})
test_that("app_check takes the slug from the app directory's name", {
local_no_electron_lookup()
appdir <- file.path(withr::local_tempdir(), "sales-dashboard")
dir.create(appdir)
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(appdir, "app.R"))
withr::local_dir(appdir)
res <- app_check(".", verbose = FALSE)
expect_false(any(grepl("slug", res$errors, fixed = TRUE)))
})
test_that("app_check returns correct structure", {
local_no_electron_lookup()
tmpdir <- tempfile()
dir.create(tmpdir)
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(tmpdir, "app.R"))
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE)
result <- app_check(tmpdir, verbose = FALSE)
expect_true(is.list(result))
expect_true("pass" %in% names(result))
expect_true("errors" %in% names(result))
expect_true("warnings" %in% names(result))
expect_true("info" %in% names(result))
})
test_that("app_check warns about an Electron that is out of support", {
skip_if_not(r_shinylive_available(), "shinylive not available")
skip_if_not_installed("renv")
local_no_electron_lookup()
local_mocked_bindings(electron_latest_version = function() "45.5.0")
tmpdir <- tempfile()
dir.create(tmpdir)
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE)
writeLines("library(shiny)\nshinyApp(ui=fluidPage(), server=function(i,o){})",
file.path(tmpdir, "app.R"))
writeLines(c("dependencies:", " electron:", " version: \"41.0.0\""),
file.path(tmpdir, "_shinyelectron.yml"))
result <- app_check(tmpdir, verbose = FALSE)
expect_true(result$pass)
expect_true(any(grepl("Electron 41", result$warnings, fixed = TRUE)))
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.