rstudio / shiny

Easy interactive web applications with R
http://shiny.rstudio.com
Other
5.34k stars 1.87k forks source link

conflict with rols package #394

Closed ecaestecker closed 9 years ago

ecaestecker commented 10 years ago

Hi,

We are currently in a testing phase for shiny, and for our purposes we would require to load the bioconductor rols package. After adding library(rols), the first refresh works fine and will load rols correctly it seems, however upon refreshing the page again after editing server.R with additional functionalities, we receive the error (described below) from line 23 in reactives.R.

Any help in resolving this bug would be highly appreciated! Evelyne

server.R:

library(shiny)
library(rols)

shinyServer(function(input, output) {
      output$Help  <- renderText({
           paste0(search(), collapse="<br>") 
      })
  })

ui.R:

library(shiny)
shinyUI(pageWithSidebar(
    headerPanel("testing rols error"),
    sidebarPanel(
      tags$style(type='text/css', "#features {height: 150px}"),
      textInput("in", "provide input")
    ),
    mainPanel(
      tableOutput("Help")
    )
))

JavaScript console error:

Listening on port 48071 Warning in .simpleDuplicateClass(def, prev) : the specification for S3 class “connection” in package ‘SSOAP’ seems equivalent to one from package ‘RJSONIO’ and is not turning on duplicate class definitions for this class Warning in .simpleDuplicateClass(def, prev) : the specification for S3 class “AsIs” in package ‘BiocGenerics’ seems equivalent to one from package ‘RJSONIO’ and is not turning on duplicate class definitions for this class Warning in .simpleDuplicateClass(def, prev) : the specification for S3 class “connection” in package ‘BiocGenerics’ seems equivalent to one from package ‘RJSONIO’ and is not turning on duplicate class definitions for this class Warning in .simpleDuplicateClass(def, prev) : the specification for S3 class “file” in package ‘BiocGenerics’ seems equivalent to one from package ‘RJSONIO’ and is not turning on duplicate class definitions for this class Warning in .simpleDuplicateClass(def, prev) : the specification for S3 class “pipe” in package ‘BiocGenerics’ seems equivalent to one from package ‘RJSONIO’ and is not turning on duplicate class definitions for this class Warning in .simpleDuplicateClass(def, prev) : the specification for S3 class “textConnection” in package ‘BiocGenerics’ seems equivalent to one from package ‘RJSONIO’ and is not turning on duplicate class definitions for this class This is 'rols' version 1.2.2 Error in lapply(.dependents$values(), function(ctx) { : attempt to apply non-function

Session info

R version 3.0.1 (2013-05-16) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics datasets grDevices utils methods base other attached packages: [1] rols_1.2.2 shiny_0.8.0 loaded via a namespace (and not attached): [1] Biobase_2.20.1 BiocGenerics_0.6.0 bitops_1.0-6 caTools_1.16 [5] codetools_0.2-8 digest_0.6.4 httpuv_1.2.1 parallel_3.0.1 [9] RCurl_1.95-4.1 RJSONIO_1.0-3 SSOAP_0.8-0 XML_3.98-1.1 [13] XMLSchema_0.7-2 xtable_1.7-1

jcheng5 commented 10 years ago

cc @lgatto

I can confirm that rols does appear to break Shiny. Even this fails:

library(rols)
shiny::runExample('01_hello')

This works though:

library(XML)
library(XMLSchema)
library(SSOAP)
library(Biobase)
shiny::runExample('01_hello')
lgatto commented 10 years ago

cc @duncantl

I think I found out what is happening, but I can't explain it. rols defines an S4 class Map and shiny has an identically named Reference class, and this, or something related to that, is at the origin of the error.
The Map class is actually a by-product of the SSOAP package, that creates the functions and data structures that handle the SOAP queries and responses automatically.

Renaming class seems to work, but before proceeding with refactoring, I would prefer to see if there was not a more elegant way to deal with this, as the same error would probably occur with other packages that depend on SSOAP as rols.

Any ideas?

duncantl commented 10 years ago

Where is the Map function defined in the SSOAP package? or is it defined by processing a WSDL document? I don't see Map defined in SSOAP or XMLSchema. If it is defined in genSOAPClientInterface(), you have control over where the classes are defined.

lgatto commented 10 years ago

Yes, it is indeed generated by genSOAPClientInterface(). The definitions are then written to a file with SSOAP:::makeTopLevelFunctions and writeLines, and shipped with the rols package where are defined. Apparently the unexported rols and shiny Map classes somehow conflict, but I don't understand why. The quickest fix would be to rename one class (which I am happy to do), but the apparent reason for this error is intriguing.

hredestig commented 10 years ago

The problem seems larger than only rols to me. I get the exact same crash with another package that I am developing but am at a loss to figure out what goes wrong... Just to say that the fix might be needed in R or shiny rather than in rols or SSOAP

lgatto commented 10 years ago

Could you provide more details or a link to the package?

hredestig commented 10 years ago

Unfortunately I can't share the whole package at this moment, trying to make a minimal version of it that still triggers the bug.. Initial guess is that the problem arises when inheriting from AssayData class from Biobase...

lgatto commented 10 years ago

Do you have a class Map in your package?

hredestig commented 10 years ago

nope

hredestig commented 10 years ago

have to give up on that for now, a barebones version of that package does not trigger the bug..

jcheng5 commented 10 years ago

cc @wch @hadley, any ideas how conflicts of unexported names might cause problems?

hadley commented 10 years ago

I wonder if it's related to https://github.com/hadley/devtools/issues/427 - it's another weird namespace-y issue with RJSONIO involved.

OTOH it may be a problem with S4 correctly identifying super classes. Does the error change if you load rols and shiny in the other order?

wch commented 10 years ago

I know that they've fixed some S4-related bugs in R-devel. It's worth trying this on the latest development version of R to see if the problem magically goes away.

lgatto commented 10 years ago

All my reports are with R-devel (svn 64910, 2014-02-01). I am happy to update and try again if the fixes are more recent.

Here is my understanding of the issue, apparently related to two classes being called Map.

library("rols")
library("shiny")
shiny::runExample("01_hello")
## Listening on port 5235
## Error in lapply(.dependents$values(), function(ctx) { : 
##   attempt to apply non-function
## Error: attempt to apply non-function

This is not the expected Map Reference class with method $values(), as defined in shiny.

rols:::getOntologyNames()
## Error in checkAtAssignment("Map", ".xData", "environment") : 
##   ‘.xData’ is not a slot in class “Map”

Again, this as not the Map S4 class as defined in rols.

Update The S4 slot should actually be .Data instead of .xData. Not really sure where that comes from - maybe from one of shiny's .env = 'environment' field.

If I do the same thing as above but load shiny first, I get this warning in addition to the last error:

> rols:::getOntologyNames()
Error in checkAtAssignment("Map", ".xData", "environment") : 
  ‘.xData’ is not a slot in class “Map”
In addition: Warning message:
In rm(list = as.character(handle), pos = .wsconns) :
  object '33858416' not found

Updating my Map to xMap seems to fix the issue with rols. I am happy to do that if no better solution is suggested.

hredestig commented 10 years ago

@lgatto how did you see that Map triggered the problem? Just guess? My package doesn't use any class names that are also used by shiny..

wch commented 10 years ago

@lgatto I think the version of R that you are using has the S4 fixes, so that's likely not the issue.

lgatto commented 10 years ago

@hredestig The checkAtAssignment error and its traceback were somehow obvious. For the first one, I had to look the offending code in the shiny repo to realise that .dependents was an instance of shiny's Map reference class. Finally, as a global rename to something else seems to fix the problem from the rols perspective, I can only conclude that this is the case, but without explaining it.

wch commented 9 years ago

@lgatto we've moved away from reference classes in Shiny. Do you mind trying this again with the development version of Shiny?

lgatto commented 9 years ago

Using the latest shiny from github:

> packageVersion("shiny")
[1] ‘0.10.1.9006’

I re-ran the chunks that resulted in errors, and all seems fine now.

> library("rols")

This is 'rols' version 1.7.1 

> library("shiny")
> shiny::runExample("01_hello")

Listening on http://127.0.0.1:5678

> rols:::getOntologyNames()
An object of class "getOntologyNamesReturn"
Slot "getOntologyNamesReturn":
Object of class "Map" with 93 items:
 Keys:   LSM, TADS, ...
 Values: Leukocyte Surface Markers, Tick Gross Anatomy, ...

Thank you very much!

wch commented 9 years ago

Excellent!

yihui commented 9 years ago

Kudos to R6! :+1: