R/mod_import.R

Defines functions mod_import_server mod_import_ui

#' import UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd 
#'
#' @importFrom shiny NS tagList 
mod_import_ui <- function(id){
  ns <- NS(id)
  tagList(
    fileInput(ns("file1"), "Upload Past Pairings", 
              accept =".xlsx"),
    textOutput(ns("status"))
  )
}
    
#' import Server Functions
#'
#' @noRd 
mod_import_server <- function(id, upload){
  moduleServer( id, function(input, output, session){
    ns <- session$ns
    
    status = rv(message = "Ready to receive")
    
    #Uploaded a file
    observeEvent(input$file1, {
      path = input$file1$datapath
      
      #TODO: Want to validate path
      
      #Load each sheet within the workbook
      sheets = readxl::excel_sheets(path)
      
      #Spec the col types for robust
      # Pass it back to the reactive
      upload$names = readxl::read_excel(path, 
                                 sheet="names",
                                 col_types = c("numeric", "text"))
      upload$past = readxl::read_excel(path, 
                                sheet="past",
                                col_types = c("date", "numeric", "numeric")) 
      #TODO: validate input
      
      
      status$message = "Ready to run"

  })
    
    
    output$status = renderText(
      status$message
    )
  })

}
    
jimr1603/coffeeRoulette documentation built on June 15, 2022, 8:35 p.m.