Skip to content

Commit

Permalink
Fix subtle name resolution bugs
Browse files Browse the repository at this point in the history
See in particular:
http://stackoverflow.com/questions/13575353/how-does-the-shiny-r-package-deal-with-data-frames

Also reported at different times by Dirk Eddelbuettel and Jay Emerson.

The observed behavior is that S3/S4 method dispatch does not always seem to
work; the desired methods are not invoked despite appearing to be in the
search path.

The problem was that sourcing files with local=TRUE creates a new environment
based on the parent frame, which in our case is Shiny's package environment.
What we really want is to read from the global environment but write to a
throwaway environment. The correct way to do that is to make a new environment
with .GlobalEnv as the parent.
  • Loading branch information
jcheng5 committed Nov 27, 2012
1 parent 1e1f4e4 commit 0b469f0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/shiny.R
Expand Up @@ -412,7 +412,7 @@ dynamicHandler <- function(filePath, dependencyFiles=filePath) {
if (file.exists(filePath)) {
local({
cacheContext$with(function() {
source(filePath, local=TRUE)
source(filePath, local=new.env(parent=.GlobalEnv))
})
})
}
Expand Down Expand Up @@ -659,7 +659,7 @@ startApp <- function(port=8101L) {
serverFileTimestamp <- NULL
local({
serverFileTimestamp <<- file.info(serverR)$mtime
source(serverR, local=TRUE)
source(serverR, local=new.env(parent=.GlobalEnv))
if (is.null(.globals$server))
stop("No server was defined in server.R")
})
Expand Down Expand Up @@ -733,7 +733,7 @@ startApp <- function(port=8101L) {
shinyServer(NULL)
local({
serverFileTimestamp <<- mtime
source(serverR, local=TRUE)
source(serverR, local=new.env(parent=.GlobalEnv))
if (is.null(.globals$server))
stop("No server was defined in server.R")
})
Expand Down

0 comments on commit 0b469f0

Please sign in to comment.