Skip to content

app_dir must be a directory containing: #277

Closed

Description

@nick-youngblut

Error:

Error in `app_initialize()`:
! `app_dir` must be a directory containing:

• an `./app.R` Shiny application

  or

• a Shiny R Markdown file
• a `./server.R` Shiny server

ℹ If a Shiny R Markdown document is found, it will be the prefered document.
ℹ `./app.R` is not compatible with Shiny R Markdown files.


ℹ You can inspect the failed AppDriver object via `rlang::last_error()$app`
ℹ AppDriver logs:
{shinytest2} R info 20:31:46.75 Start AppDriver initialization
{shinytest2} R info 20:31:46.75 Starting Shiny app
{shinytest2} R info 20:31:46.75 Error while initializing AppDriver:
                                `app_dir` must be a directory containing:
                                
                                • an `./app.R` Shiny application
                                
                                  or
                                
                                • a Shiny R Markdown file
                                • a `./server.R` Shiny server
                                
                                ℹ If a Shiny R Markdown document is found, it will be the prefered document.
                                ℹ `./app.R` is not compatible with Shiny R Markdown files.

Caused by error in `generic_abort()`:
! `app_dir` must be a directory containing:

• an `./app.R` Shiny application

  or

• a Shiny R Markdown file
• a `./server.R` Shiny server

ℹ If a Shiny R Markdown document is found, it will be the prefered document.
ℹ `./app.R` is not compatible with Shiny R Markdown files.
Run `rlang::last_error()` to see where the error occurred

My app.R file is the base directory of my project, where I am running shinytest2::record_test(). My app.R file:

library(shiny)
source('./ui.R')
source('./server.R')
shinyApp(server=server, ui=ui)

I'm using v0.2.0 of shinytest2

Activity

  1. schloerke commented on Nov 10, 2022

    @schloerke
    Collaborator

    The check is done here:

    has_app_path <- fs::file_exists(fs::path(app_dir, "app.R"))
    has_server_path <- fs::file_exists(fs::path(app_dir, "server.R"))
    rmds <- app_dir_rmd(self, private, app_dir)
    # if (length(rmds) > 1) {
    # app_abort(self, private, "For testing, only one .Rmd file is allowed per directory.")
    # }
    if (length(rmds) > 0 && has_app_path) {
    # Has an Rmd and an app.R
    generic_abort()
    }
    # Rmd + server.R is allowed! Use Rmd path
    # No Rmd, but has app.R or server.R
    if (has_app_path && has_server_path) {
    generic_abort()
    }

    I don't see why you're getting the error. Do you have a shiny rmarkdown quarto file in the same folder?

  2. GitHunter0 commented on Nov 10, 2022

    @GitHunter0

    I'm having the same issue in Windows 10, I can't find a way to use shinytest2

  3. schloerke commented on Nov 10, 2022

    @schloerke
    Collaborator

    @GitHunter0 Can you provide a screen cap of your app folder contents and you running the minimal amount of code needed to produce the error? It is difficult for me to debug an error I can not reproduce locally. Thank you

  4. GitHunter0 commented on Nov 10, 2022

    @GitHunter0

    For sure @schloerke , this is my MWE for you to check:

    Root project folder "shinytest2" containing:

        app.R
        global.R
        server.R
        shinytest2.Rproj
        ui.R
    
    # app.R
    
    shiny::runApp(appDir = ".")
    
    # global.R 
    
    library(shiny)
    
    # ui.R 
    
    ui <- bslib::page_navbar(
    
      theme = bslib::bs_theme(version=5),
    
      tabPanel(value = "tab1",
        
        textInput("in1", "Enter text"),
        verbatimTextOutput("out1")
      )
    
    )
    
    # server.R
    
    server <- function(input, output, session) {
      
      output$out1 <- renderPrint({ input$in1 })
    }
    

    Then I type shinytest2::record_test(".") in the console (with the root project folder as the working directory) and get this error message:

    shinytest2::record_test(".")
    #> Error in `app_initialize()`:
    #> ! Error starting shiny application:
    #> Loading required package: shiny
    #> Warning: package 'shiny' was built under R version 4.2.2
    #> Error in shinyAppDir(x) : App dir must contain either app.R or server.R.
    #> 
    #> 
    #> ℹ You can inspect the failed AppDriver object via `rlang::last_error()$app`
    #> ℹ AppDriver logs:
    #> {shinytest2} R info   17:12:57.09 Start AppDriver initialization
    #> {shinytest2} R info   17:12:57.09 Starting Shiny app
    #> {shinytest2} R info   17:12:58.58 Error while initializing AppDriver:
    #>                                   Error starting shiny application:
    #>                                   Loading required package: shiny
    #>                                   Warning: package 'shiny' was built under R version 4.2.2
    #>                                   Error in shinyAppDir(x) : App dir must contain either app.R or server.R.
    #> {shiny}      R stderr ----------- Loading required package: shiny
    #> {shiny}      R stderr ----------- Warning: package 'shiny' was built under R version 4.2.2
    #> {shiny}      R stderr ----------- Error in shinyAppDir(x) : App dir must contain either app.R or server.R.
    #> 
    #> Caused by error in `app_start_shiny()`:
    #> ! Error starting shiny application:
    #> Loading required package: shiny
    #> Warning: package 'shiny' was built under R version 4.2.2
    #> Error in shinyAppDir(x) : App dir must contain either app.R or server.R.

    Created on 2022-11-10 by the reprex package (v2.0.1)

    R version 4.2.1 (2022-06-23 ucrt)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    Running under: Windows 10 x64 (build 19045)
    
    other attached packages:
    [1] shinytest2_0.2.0 testthat_3.1.4  
    [3] shiny_1.7.3     
    

    I appreciate if you can help, maybe it's a simple mistake.

  5. schloerke commented on Nov 10, 2022

    @schloerke
    Collaborator

    Thank you!

    Ah. I didn't see it earlier.

    Please remove your app.R file as your App logic is contained in ui.R/server.R. Either use app.rORui.R/server.R`. The error was being hit on this line of logic. We could probably have a cleaner error message.

    Example with an app with just a server.R and ui.R: https://github.com/rstudio/shinytest2/tree/9e5ac958dea15cd3b11123bbfb024397ae178209/tests/testthat/apps/files-server-ui

    (The global.R should not make a difference to {shinytest2}. If it does, please let me know.)

  6. GitHunter0 commented on Nov 10, 2022

    @GitHunter0

    Thank you @schloerke , now it's working as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions