Skip to content

Clarify when local_app_support() is needed vs package functions#438

Merged
schloerke merged 9 commits intomainfrom
copilot/update-local-app-support-example
Feb 9, 2026
Merged

Clarify when local_app_support() is needed vs package functions#438
schloerke merged 9 commits intomainfrom
copilot/update-local-app-support-example

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 9, 2026

Users were unclear when local_app_support() is required, particularly for inline apps where package functions are already available via library() or devtools::load_all().

Changes

Roxygen documentation (R/test-app.R)

  • Added sections distinguishing inline apps (no local_app_support() needed) from directory-based apps (needed)
  • Clarified differences between local_app_support(), with_app_support(), and load_app_support()
  • Expanded examples to cover real-world scenarios

Vignette (vignettes/use-package.Rmd)

  • New section "Understanding app support files" with decision tree for function selection
  • Code examples showing when each approach applies

FAQ (vignettes/zzz-faq.Rmd)

  • Added note that inline apps don't require app support functions
  • Cross-reference to detailed vignette section

Example

This does not need local_app_support():

test_that("inline app with package modules works", {
  # mod_test_ui already available from package
  test_app <- shinyApp(
    ui = fluidPage(mod_test_ui("test")),
    server = function(input, output, session) {
      mod_test_server(id = "test")
    }
  )
  app <- AppDriver$new(test_app)
})

This does need it:

test_that("app with separate support files", {
  app_dir <- system.file("myapps/app1", package = "mypkg")
  local_app_support(app_dir)  # Loads app1/R/*.R files
  
  expect_true(exists("my_module_ui"))  # From app1/R/
  app <- AppDriver$new(app_dir)
})
Original prompt

This section details on the original issue you should resolve

<issue_title>How to use local_app_support() with AppDriver</issue_title>
<issue_description>Hello,

I have a shiny app that I want to test as part of a package. The app uses package functions, but currently I"m getting an error that the package is not found during test because it's not installed but loaded with devtools.

I read that the new local_app_support() function is designed to help here, but I don't know how to use it with a test app and the app driver. For example

# App with modules
testApp <- shinyApp(
    ui <- fluidPage(
      mod_test_ui("test")
    ),
    server <- function(input, output, session) {
      mod_test_server(id = "test")
    }
  )

# Start app and click option 4
app <- AppDriver$new(app = testApp)
app$set_inputs("test-option" = "4")

This is not a fully reproducible example because you'd need the whole package, but where in this code do I add local_app_support() such that I don't get the error: "packagename" not found, during testing. local_app_support requires an app_dir argument, but I don't have that given my app is passed as a variable to the AppDriver.

I hope I made the issue clear, but feel free to ask for more details!

Thanks</issue_description>

<agent_instructions>Expand upon the documentation so there is no doubt in the benefits.

Expand upon the vignette usage for the app support methods.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@schloerke @pieterjanvc Thank you for your patience! I hope this write up helps with the confusion. I'll adjust the issue to request better docs.

When using inline apps like in your example, there is no need for local_app_support() as you can get access to anything you need by rearranging your helper functions. Ex, your mod_test_ui would be within the test file or your package and you could test it directly.

So, hopefully no need for local_app_supprt() when writing inline tests


However, Let's imagine your file structure looks like:

# File: ./inst/myapps/app1/R/app.R

app1_ui <- fluidPage(my_module_ui("test"))
app1_server <- function(input, output, session) {
  mod_test_server(id = "test")
}

shinyApp(ui = app1_ui, server = app1_server)
# File: ./inst/myapps/app1/R/mymods.R
mod_test_ui <- #.... actually put code here ...
mod_test_server <- #.... actually put code here ...

You can add a test file for your package that attempts to access the test app information without clobbering your whole test file.

Ex test file within {mypkg}'s tests:

# File: ./tests/testthat/test-app1.R

# Does NOT exist
expect_true(!exists("my_module_ui"))

test_that("app1 loads default values", {

  # Does NOT exist
  expect_true(!exists("my_module_ui"))

  local_app_support(system.file("myapps/app1", package = "mypkg"))

  # DOES exist ; <-- Goal achieved!
  expect_true(exists("my_module_ui"))

})

# Does NOT exist
expect_true(!exists("my_module_ui"))

For an internal test example... this test looks for a test app and loads its supporting files into the local() call:

test_that("app support loading works", {
skip_if_no_apps()
expect_false(exists("n"))
local({
local_app_support(app_dir = test_path("apps/wait"))
expect_true(exists("n"))
expect_equal(n, 750)
})
expect_false(exists("n"))
})

which loads this value:


Related... An internal test showing that internal and exported package values are available in different contexts.

Values:

expkg_internal_value <- "expkg internal value"
#' Exported docs
#' @export
expkg_exported_value <- "expkg exported value"

Availability:

  • In testing: both values readily available.

    test_that("Local pkg loads", {
    # No library calls!
    # expkg should be auto loaded by testthat
    expect_equal(expkg_internal_value, "expkg internal value")
    expect_equal(expkg_exported_value, "expkg exported value")
    })

  • Within app: Neither value is available until a library() or require() call within your app.

    testthat::expect_false(exists("expkg_exported_value"))
    testthat::expect_true(require(expkg)) # This also attaches the package
    testthat::expect_true(is.function(expkg_shiny_app))
    testthat::expect_equal(expkg_exported_value, "expkg exported value")
    testthat::expect_false(exists("expkg_internal_value"))
    testthat::expect_equal(expkg:::expkg_internal_value, "expkg internal value")


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 9, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ schloerke
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 3 commits February 9, 2026 18:42
Co-authored-by: schloerke <93231+schloerke@users.noreply.github.com>
Co-authored-by: schloerke <93231+schloerke@users.noreply.github.com>
Co-authored-by: schloerke <93231+schloerke@users.noreply.github.com>
Copilot AI changed the title [WIP] Update example for local_app_support usage with AppDriver Clarify when local_app_support() is needed vs package functions Feb 9, 2026
Copilot AI requested a review from schloerke February 9, 2026 18:47
@schloerke
Copy link
Copy Markdown
Collaborator

@copilot Add news bullet. Your PR is 438

Copy link
Copy Markdown
Collaborator

@schloerke schloerke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Resolve these suggestions.

Copilot stopped work on behalf of schloerke due to an error February 9, 2026 20:13
@schloerke schloerke marked this pull request as ready for review February 9, 2026 20:24
@schloerke schloerke merged commit d5e30a5 into main Feb 9, 2026
18 of 19 checks passed
@schloerke schloerke deleted the copilot/update-local-app-support-example branch February 9, 2026 20:24
@github-actions github-actions bot restored the copilot/update-local-app-support-example branch February 9, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to use local_app_support() with AppDriver

3 participants