R/mod_courtview.R

Defines functions mod_courtview_server mod_courtview_ui

#' courtview UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd 
#'
#' @importFrom shiny NS tagList 
#' @importFrom dplyr tribble
#' @import ggplot2


mod_courtview_ui <- function(id){
  ns <- NS(id)
  tagList(
    div(
      id = ns("crt_stp"),
      class = "court",
      plotOutput(ns("crt"))
      
    )
 
  )
}
    
#' courtview Server Function
#'
#' @noRd 
mod_courtview_server <- function(input, output, session, pnt){
  ns <- session$ns
  
  ddf <- tribble(
    ~xmn, ~xmx, ~ymn, ~ymx, ~alph,
    0, 36, 0, 39, 0.7,
    0, 36, 39, 78, 0.7,
    0, 4.5, 0, 78, 0,
    31.5, 36, 0, 78, 0,
    4.5, 18, 39, 60, 0,
    18, 31.5, 39, 60, 0,
    4.5, 18, 18, 39, 0,
    18, 31.5, 18, 39, 0
  )
  
  observe({
    df <- pnt$lastshot
    req(nrow(df) > 0)
    save(df, file = "lastShot.Rda")
    output$crt <- renderPlot({
      crt + 
        geom_point( data = df, aes(x = pbncx, y = pbncy), colour = "yellow") +
        geom_point( data = df, aes(x = phitrfx, y = phitrfy), colour = "red") +
        geom_point( data = df, aes(x = phitlfx, y = phitlfy), colour = "red") +
        geom_point( data = df, aes(x = pcngx, y = pcngy), colour = "yellow") +
        geom_point( data = df, aes(x = prcvrrfx, y = prcvrrfy), colour = "red") +
        geom_point( data = df, aes(x = prcvrlfx, y = prcvrlfy), colour = "red") 
        
      
      
    })
  })
  
  
  crt <- ggplot() + 
    geom_rect(data = ddf, aes(xmin = xmn, xmax = xmx, 
                              ymin = ymn, ymax = ymx),
              fill = "#7f966a", colour = "white") + 
    coord_fixed() + 
    scale_y_reverse() + 
    # ylim(-10, 88) + xlim(-8, 46) +
    theme_minimal() + 
    theme(legend.position = "none", 
          panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
          panel.background = element_rect(fill = "#30a0ce"),
          plot.background = element_rect(fill = "#7f966a"))
  
  output$crt <- renderPlot({
    crt
  })

}
    
## To be copied in the UI
# mod_courtview_ui("courtview_ui_1")
    
## To be copied in the server
# callModule(mod_courtview_server, "courtview_ui_1")
 
joeheywood/tnsinp documentation built on Aug. 3, 2020, 8:35 a.m.