R/shiny_update_r.R

Defines functions Shiny_App_Update Data_Update Shiny_Update

Documented in Data_Update Shiny_App_Update Shiny_Update

#' Create Fantasy Football Data for Shiny App
#'
#' Updates Data and refreshes Shiny APP
#'
#' @param season \code{numeric}. Defaults to 2021 season
#'            \itemize{\item \code{"2021"}
#'            }
#'
#' @param vartype \code{Charcater}. Choose between season data or weekly data
#'            \itemize{
#'             \item \code{"Season"}
#'             \item \code{"Weekly"}
#'            }
#'
#' @param season \code{numeric}. Defaults to 2021 season
#'            \itemize{\item \code{"2021"}
#'            }
#'
#' @param varweek \code{numeric}. For Weekly data set to week #. 0 = Season
#'            \itemize{ \item \code{"0"}
#'            }
#'
#' @param gtype \code{Charcater}. Choose data aggregation type
#'            \itemize{
#'             \item \code{"average"}
#'             \item \code{"weighted"}
#'            }
#'
#' @param wrkdir \code{Charcater}. Set local work directory
#'
#' @export
#'

Shiny_Update <- function(season = 2021, vartype = c("Season", "Weekly"), varweek = 0, gtype = c("average","weighted"), wkdir){

  message("Load Packages and setting vars")

  setwd(wkdir)
  #source(paste0(getwd(),"/Code/Functions.R"))
  varseason <<- season
  vartype <<- vartype
  varweek <<- varweek
  gtype <<- gtype
  player_table <<- ffanalytics::ff_player_data

  #data_scrape() # Uncomment this

  #cat("",sep = "\n")
  #save(QB,RB,WR,TE,K,DST, file = paste0(getwd(),"/FantasyFootballApp/data/Raw_Data.rdata"))
  #rm(QB,RB,WR,TE,K,DST,DataAllOff,drops,keeps)

  #BalanceAnalysis()
  #cat("",sep = "\n")
  #rm(YdsData,tdData,recData,receiving_data, data, tm)

  #Create projections for each format
  CreateProjections()

  #message("Starting App Deploy")
  #deployApp(paste0(getwd(),"/FantasyFootballApp"), forceUpdate = TRUE)
  #message("Finished Season Run")


}

#' Updates Data
#'
#' @param season \code{numeric}. Defaults to 2021 season
#'            \itemize{\item \code{"2021"}
#'            }
#'
#' @param vartype \code{Charcater}. Choose between season data or weekly data
#'            \itemize{
#'             \item \code{"Season"}
#'             \item \code{"Weekly"}
#'            }
#'
#' @param season \code{numeric}. Defaults to 2021 season
#'            \itemize{\item \code{"2021"}
#'            }
#'
#' @param varweek \code{numeric}. For Weekly data set to week #. 0 = Season
#'            \itemize{ \item \code{"0"}
#'            }
#'
#' @param gtype \code{Charcater}. Choose data aggregation type
#'            \itemize{
#'             \item \code{"average"}
#'             \item \code{"weighted"}
#'            }
#'
#' @param wrkdir \code{Charcater}. Set local work directory
#'
#' @export
#'
Data_Update <- function(season = 2021, vartype = c("Season", "Weekly"), varweek = 0, gtype = c("average","weighted"), wkdir){


  setwd(wkdir)
  varseason <<- season
  vartype <<- vartype
  varweek <<- varweek
  gtype <<- gtype
  player_table <<- ffanalytics::ff_player_data

  data_scrape() # Uncomment this
  cat("",sep = "\n")
  save(QB,RB,WR,TE,K,DST, file = paste0(getwd(),"/FantasyFootballApp/data/Raw_Data.rdata"))
  #rm(QB,RB,WR,TE,K,DST,DataAllOff,drops,keeps, varseason, vartype, gtype)


}

#' Update Shiny App
#'
#' @export
#'

Shiny_App_Update <- function() {

  deployApp(paste0(getwd(),"/FantasyFootballApp"), forceUpdate = TRUE)
  message("Finished Season Run")

}
RandalMorris/AnalyticsFootball documentation built on Dec. 18, 2021, 9:52 a.m.