11.15 LOADING THINGS (2)

  • Code outside server <- function(input, output) {} is run once, when you launch your app

  • Code inside server <- function(input, output) {} is run once each time a user visits your app

  • Code inside render* functions is rerun constantly (not only when user changes widget value, see [reactivity(http://shiny.rstudio.com/articles/understanding-reactivity.html)])

  • That means…

    • Load Source scripts, libraries, and data outside of server function (at the beginning)
      • Store data in www/ folder in your app directory
      • Access with read.table("www/swiss.csv", sep=",")
      • Access online data by inserting the url into the read* function (e.g. read.table())
    • User specific objects (e.g. object that records user’s session information) are defined inside shinyServer’s unnamed function, but outside of any render* calls
      • e.g. user registers himself, user data as input data (compare income)
    • Code/objects that are affected by choices in widgets must be placed witin the a render* function
      • Shiny reruns code in a render* chunk each time a user changes a widget mentioned in the chunk
  • Avoid placing code within render function that does not need to be there… for performance reasons!

  • Example