I'm making a baseball application to view visuals of pitching and hitting data we collect and am running into an error. This is what is stated on my browser when I upload it,
An error has occurred
The application failed to start (exited with code 1).
Error in value[3L] : invalid multibyte string at ' L'
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Here is my code:
library(shiny)
library(ggplot2)
library(shinythemes)
library(rmarkdown)
num <- read.csv('Fall 2019 Pitching Stats.csv',encoding="UTF-8")
data <- read.csv('Fall 2019 Hitting Stats.csv',encoding="UTF-8")
server <- function(input,output,session) {
pitch.plot <- reactive({
num.input.player <- subset(num,Pitcher==input$player)
num.input.date <- subset(num.input.player,Date == input$date)
plot <- ggplot(data=num.input.date,aes(x=HB,y=VB,color=Pitch.Type))
plot + geom_point(size=3,stroke=2) + theme_minimal() +
lims(x=c(-25,25),y=c(-25,25)) +
theme_minimal() +
coord_fixed() +
geom_vline(xintercept = 0) + geom_hline(yintercept = 0) + xlab("Horizontal Break") +
ylab ("Vertical Break") +
ggtitle("Horizontal & Vertical Break Report") +
theme(axis.title.x = element_text(color="Black",size=18),
axis.title.y=element_text(color="Black",size=18),
axis.text.x=element_text(size=20),
axis.text.y=element_text(size=20),
legend.title = element_text(size=20),
legend.text = element_text(size=20),
plot.title = element_text(color="Black",
size=20))
})
pitch.line <- reactive({
num.player <- subset(num,Pitcher==input$player)
num.date <- subset(num.player,Date == input$date)
line <- ggplot(data=num.date)
line + geom_line(aes(x=Pitch.Count,y=Speed,color=Pitch.Type),size = 3)
})
spin.line <- reactive({
num.player.spin <- subset(num,Pitcher==input$player)
num.date.spin <- subset(num.player.spin,Date == input$date)
line <- ggplot(data=num.date.spin)
line + geom_line(aes(x=Pitch.Count,y=Spin,color=Pitch.Type),size = 3)
})
output$bptable <- renderTable({
num.player.bp <- subset(num,Pitcher==input$player)
num.date.bp <- subset(num.player.bp,Date == input$date)
num.date.bp
})
hit.spin <- reactive({
batter.num <- subset(data,Batter==input$hitter)
line.g <- ggplot(data=batter.num,aes(x=Distance,y=Exit.Speed))
line.g + geom_line(aes(color=Batter),size=3)
})
output$plotgraph1 = renderPlot({pitch.plot()})
output$plotgraph2 = renderPlot({pitch.line()})
output$plotgraph3 = renderPlot({spin.line()})
output$plotgraph4 = renderPlot({hit.spin()})
}
ui <- navbarPage(strong("Hofstra Baseball Analytics"),theme = shinytheme("cerulean"),
tabPanel("Hitting Report",
sidebarPanel(
selectInput("hitter","Choose Player",data$Batter),
),
mainPanel(
tabsetPanel(
tabPanel("Exit Velocity",plotOutput("plotgraph4"))
)
)
),
tabPanel("Bullpen Report",
sidebarLayout(
sidebarPanel(
selectInput("player","Choose Player",num$Pitcher),
selectInput("date","Choose a Date",num$Date)
),
mainPanel(
tabsetPanel(
tabPanel("HB vs. VB",plotOutput("plotgraph1")),
tabPanel("Speed Graph",plotOutput("plotgraph2")),
tabPanel("Spin Graph", plotOutput("plotgraph3")),
tabPanel("Output Table",tableOutput("bptable"))
)
)
)
)
)
shinyApp(ui = ui, server = server)