rstudio / shiny-examples

Other
1.95k stars 3.78k forks source link

How Code Scripts Interact With Each Other #198

Closed solomondaner closed 2 years ago

solomondaner commented 2 years ago

I see the two files "bloomfilter.R" and "global.R" are being used to get the livestream data. However, although I see some functions in "global.R" being used in Server.R, I don't see those two actual files being imported into Server.R. How does that work? And where are the functions in bloomfilter.R being used in the Server.R code?

pyltime commented 2 years ago

Code in a global.R file will always be loaded into the global environment of any Shiny app even if not directly loaded in the server.R file - see the "Global Objects" section here. Since bloomfilter.R is being loaded in global.R, it gets imported through that.

The Bloomfilter code gets used in the global.R code, which again, is imported by server.R.

solomondaner commented 2 years ago

I see, what is the benefit in producing 2 additional files outside the Server.R file?

jcheng5 commented 2 years ago

In this case, for clarity only. For a real app, you might have your functions defined separately if you want to write unit tests for them, or reuse them from a related but separate script/notebook/document.