7

I have a shiny app using the package shinydashboard.

At first, I had all the files as 3 files - global.R, server.R, ui.R.

As files got bigger and messy, I took out the codes for each menus, and placed them in a separate folder. (splitting shiny files - http://shiny.rstudio.com/articles/scoping.html)

everything works, but there's something annoying happening - it displays 'TRUE' at the bottom of the ui of the menus I split into separate folder.

If everything is just in one big file, it doesn't display TRUE.

anyone know why this is happening?

functionally, everything is same.

zx8754
  • 52,746
  • 12
  • 114
  • 209
jae555
  • 140
  • 2
  • 7
  • I don't even get a true-value return. Insted I get this error message: ERROR: cannot coerce type 'closure' to vector of type 'character' – XerXes Oct 15 '15 at 14:06

1 Answers1

20

What's happening is that source returns a list with 2 things inside: value which is the actual R code inside, and visible which is whether or not the code returned visibly or invisibly. The TRUE you are seeing is a reflection of the fact that the code returned visibly.

What you want to do is include the value of that list. So instead of

source("file.R", local = TRUE)

Change it to

source("file.R", local = TRUE)$value

That should fix it

DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • thanks, where do i find more documentation about things like this? – jae555 Jun 01 '15 at 15:07
  • 5
    I just figured it out from manual debugging. I wasn't sure why `TRUE` is being returned, so I assigned `source(...)` to a variable and looked what that variable holds inside it. I noticed it has those two elements. I then read what the `visible` return value means and then tried changing it to be `FALSE` and saw that indeed now `FALSE` is being printed, so I tried explicitly using the `value` and it worked – DeanAttali Jun 01 '15 at 17:19
  • Thanks @daattali! (Is that a bug or normal behavior? I've seen that you left a comment on rstudio scoping article, great) – popo Aug 07 '15 at 13:07
  • I suppose that's normal behaviour – DeanAttali Aug 07 '15 at 14:34