Shiny: functions defined in app.R not visible to other files sourced later -


so, hit strange problem (i think) function defined in app.r not visible in r script source later on. whereas, works fine if use same function regular r script.

here reproducible code:

app.r:

library(shiny)  f1 <- function(x) {   x }  source('plot/plot.r')  ui <- fluidpage(     h1('mpg plot'),     plotoutput('plot1') )  server <- function(input, output) {   output$plot1 <- renderplot({     getplot()   }) }  shinyapp(ui = ui, server = server) 

plot/plot.r:

getplot <- function() {   cat(f1(10))   plot(mtcars$wt, mtcars$mpg) } 

here error complaining function f1 not found:

runapp()

listening on http://127.0.0.1:5254 warning: error in cat: not find function "f1" stack trace (innermost first):     78: cat     77: getplot [plot/plot.r#3]     76: renderplot [c:\users\tumulurig3\documents\rprojects\cancergeneexp\junk/app.r#16]     68: output$plot1      1: runapp 

whereas when place function in script, let call f.r, , source in app.r, works fine.

why function defined in global environment not visible later script?

version info:

packageversion('shiny') [1] ‘0.13.2’ version                _                                           platform       x86_64-w64-mingw32                          arch           x86_64                                      os             mingw32                                     system         x86_64, mingw32                             status         revised                                     major          3                                           minor          2.4                                         year           2016                                        month          03                                          day            16                                          svn rev        70336                                       language       r                                           version.string r version 3.2.4 revised (2016-03-16 r70336) nickname       secure dishes             

running exact same problem on windows install, , on rhel install.


Comments