-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
41 lines (33 loc) · 1.79 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(RSQLite)
library(plotly)
db <- dbConnect(RSQLite::SQLite(),"fgleaders.sqlite")
# Define server logic required to draw the 3-D plot
shinyServer(function(input, output) {
output$warPlot <- renderPlotly({
input$submitButton
# generate yearly stats based on input$year and input$team from ui.R
fgyear <- isolate(dbGetQuery(db,'SELECT * FROM fg2000s WHERE "Season" = :x AND "PA" >= :y',
params = list(x = input$year, y = input$plateapp)))
isolate(if(input$allteams==FALSE){
fgyear <- fgyear[which(fgyear$Team==input$team),]})
charttitle <- isolate(paste(input$year," ",if(input$allteams==FALSE){input$team} else{"All Teams"},sep=""))
# get specific required stats for chart and give names
WAR_stats <- data.frame(fgyear$Bat,fgyear$BsR,fgyear$Def,fgyear$Name,fgyear$WAR)
names(WAR_stats) <- c("Batting","Baserunning","Fielding","Name","WAR")
# plot the stats
plot_ly(data=WAR_stats, x=~Batting,y=~Baserunning,z=~Fielding,
mode="markers",color=~WAR,text=~Name,hoverinfo="text",
marker=list(colorbar=list(title="Total WAR"))) %>%
layout(margin=list(t=75),title = charttitle, titlefont = list(size=24),
scene=list(aspectmode="data",camera=list(eye=list(x=1,y=-2.5,z=0.5))))
})
})