Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object not found error from within the session #381

Open
pawelru opened this issue Apr 2, 2024 · 0 comments
Open

object not found error from within the session #381

pawelru opened this issue Apr 2, 2024 · 0 comments

Comments

@pawelru
Copy link

pawelru commented Apr 2, 2024

It seems to me that the shiny session does not respect the searchpath of the parent R session and throws the "object not found" type of errors for object that are findable in the standard workflow

Minimal reprex:

library(teal.modules.clinical)
#> Loading required package: teal
#> Loading required package: shiny
#> Loading required package: teal.data
#> Loading required package: teal.code
#> Loading required package: teal.slice
#> Registered S3 method overwritten by 'teal':
#>   method        from      
#>   c.teal_slices teal.slice
#> 
#> You are using teal version 0.15.2.9016
#> 
#> Attaching package: 'teal'
#> The following objects are masked from 'package:teal.slice':
#> 
#>     as.teal_slices, teal_slices
#> Loading required package: teal.transform
#> Loading required package: tern
#> Loading required package: rtables
#> Loading required package: formatters
#> Loading required package: magrittr
#> 
#> Attaching package: 'rtables'
#> The following object is masked from 'package:utils':
#> 
#>     str
#> Registered S3 method overwritten by 'tern':
#>   method   from 
#>   tidy.glm broom
library(shiny)

ui <- fluidPage(
  titlePanel("Simple Shiny App"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("num_points", "Number of Points", min = 10, max = 100, value = 50)
    ),
    mainPanel(
      plotOutput("scatter_plot")
    )
  )
)
server <- function(input, output) {
  print(search())
  print(obj_label)
  output$scatter_plot <- renderPlot({
    x <- rnorm(input$num_points)
    y <- rnorm(input$num_points)
    plot(x, y, main = "Scatter Plot", xlab = "X", ylab = "Y")
  })
}
app <- shinyApp(ui, server)

app_driver <- shinytest2::AppDriver$new(app)

app_driver$get_logs()
#> {shinytest2} R  info   17:43:47.75 Start AppDriver initialization
#> {shinytest2} R  info   17:43:47.78 Starting Shiny app
#> {shinytest2} R  info   17:43:48.44 Creating new ChromoteSession
#> {shinytest2} R  info   17:43:49.03 Navigating to Shiny app
#> {shinytest2} R  info   17:43:49.05 Injecting shiny-tracer.js
#> {chromote}   JS info   17:43:49.06 shinytest2; jQuery found
#> {chromote}   JS info   17:43:49.07 shinytest2; Waiting for shiny session to connect
#> {chromote}   JS info   17:43:49.07 shinytest2; Loaded
#> {shinytest2} R  info   17:43:49.07 Waiting for Shiny to become ready
#> {chromote}   JS info   17:43:49.12 shinytest2; Connected
#> {shinytest2} R  info   17:43:49.19 Waiting for Shiny to become idle for 200ms within 15000ms
#> {chromote}   JS info   17:43:49.19 shinytest2; Waiting for Shiny to be stable
#> {chromote}   JS info   17:43:49.40 shinytest2; Shiny has been idle for 200ms
#> {shinytest2} R  info   17:43:49.40 Shiny app started
#> {shiny}      R  stderr ----------- Loading required package: shiny
#> {shiny}      R  stderr ----------- Running application in test mode.
#> {shiny}      R  stderr ----------- 
#> {shiny}      R  stderr ----------- Listening on http://127.0.0.1:7424
#> {shiny}      R  stderr ----------- Warning: Error in server: object 'obj_label' not found
#> {shiny}      R  stderr -----------   52: print
#> {shiny}      R  stderr -----------   51: server [<text>#17]
#> {shiny}      R  stderr -----------   14: <Anonymous>
#> {shiny}      R  stderr -----------   12: <Anonymous>
#> {shiny}      R  stderr -----------   11: <Anonymous>
#> {shiny}      R  stderr -----------   10: base::do.call
#> {shiny}      R  stderr -----------    9: base::saveRDS
#> {shiny}      R  stderr -----------    8: base::withCallingHandlers
#> {shiny}      R  stderr -----------    7: doTryCatch
#> {shiny}      R  stderr -----------    6: tryCatchOne
#> {shiny}      R  stderr -----------    5: tryCatchList
#> {shiny}      R  stderr -----------    2: tryCatchList
#> {shiny}      R  stderr -----------    1: base::tryCatch
#> {shiny}      R  stderr ----------- Error in server(...) : object 'obj_label' not found
#> {shiny}      R  stdout -----------  [1] ".GlobalEnv"        "package:shiny"     "package:stats"    
#> {shiny}      R  stdout -----------  [4] "package:graphics"  "package:grDevices" "package:utils"    
#> {shiny}      R  stdout -----------  [7] "package:datasets"  "package:methods"   "Autoloads"        
#> {shiny}      R  stdout ----------- [10] "tools:callr"       "package:base"
app_driver$stop()

Created on 2024-04-02 with reprex v2.1.0

This object should be available through the chain of Depends:

library(teal.modules.clinical)
#> Loading required package: teal
#> Loading required package: shiny
#> Loading required package: teal.data
#> Loading required package: teal.code
#> Loading required package: teal.slice
#> Registered S3 method overwritten by 'teal':
#>   method        from      
#>   c.teal_slices teal.slice
#> 
#> You are using teal version 0.15.2.9016
#> 
#> Attaching package: 'teal'
#> The following objects are masked from 'package:teal.slice':
#> 
#>     as.teal_slices, teal_slices
#> Loading required package: teal.transform
#> Loading required package: tern
#> Loading required package: rtables
#> Loading required package: formatters
#> Loading required package: magrittr
#> 
#> Attaching package: 'rtables'
#> The following object is masked from 'package:utils':
#> 
#>     str
#> Registered S3 method overwritten by 'tern':
#>   method   from 
#>   tidy.glm broom
print(obj_label)
#> new("standardGeneric", .Data = function (obj) 
#> standardGeneric("obj_label"), generic = "obj_label", package = "formatters", 
#>     group = list(), valueClass = character(0), signature = "obj", 
#>     default = NULL, skeleton = (function (obj) 
#>     stop(gettextf("invalid call in method dispatch to '%s' (no default method)", 
#>         "obj_label"), domain = NA))(obj))
#> <bytecode: 0x122862e80>
#> <environment: 0x12285fa50>
#> attr(,"generic")
#> [1] "obj_label"
#> attr(,"generic")attr(,"package")
#> [1] "formatters"
#> attr(,"package")
#> [1] "formatters"
#> attr(,"group")
#> list()
#> attr(,"valueClass")
#> character(0)
#> attr(,"signature")
#> [1] "obj"
#> attr(,"default")
#> `\001NULL\001`
#> attr(,"skeleton")
#> (function (obj) 
#> stop(gettextf("invalid call in method dispatch to '%s' (no default method)", 
#>     "obj_label"), domain = NA))(obj)
#> attr(,"class")
#> [1] "standardGeneric"
#> attr(,"class")attr(,"package")
#> [1] "methods"

Created on 2024-04-02 with reprex v2.1.0

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

No branches or pull requests

1 participant